Skip to content

Instantly share code, notes, and snippets.

@nelix
Created October 25, 2012 05:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelix/3950529 to your computer and use it in GitHub Desktop.
Save nelix/3950529 to your computer and use it in GitHub Desktop.
Chrome extension which reloads all unpacked extensions on opening of a url, for use with gruntjs's watch task.
/*
* Use with grunt-exec command: 'open -a "/Applications/Google Chrome.app" file://localhost/reload'
*/
chrome.webRequest.onBeforeRequest.addListener(hook, {urls: ['file://localhost/reload*']});
function hook(details) {
console.log('reloading all dev extensions');
chrome.management.getAll(function(extensions){
for(var i in extensions){
extension = extensions[i];
if (extension.installType == "development" && extension.enabled && extension.name != "Reload Extension") {
chrome.management.setEnabled(extension.id, false, function(){
chrome.management.setEnabled(extension.id, true);
});
}
}
});
chrome.tabs.remove(details.tabId);
}
{
"name": "Reload Extension",
"version": "1",
"description": "Reload chrome extension",
"permissions": ["management", "tabs", "webRequest", "file://localhost/reload*"],
"background": {"scripts":["background.js"]},
"manifest_version": 2
}
@nelix
Copy link
Author

nelix commented Oct 25, 2012

The grunt-exec task is this:

 exec: {
  reload_chrome_extension: {
    command: 'open -a "/Applications/Google Chrome.app" file://localhost/reload'
},
watch: {
  files: '**/*.js',
  tasks: 'exec:reload_chrome_extension'
}

@nelix
Copy link
Author

nelix commented Oct 25, 2012

Fixed missing .id for reenabling the extension.

@nelix
Copy link
Author

nelix commented Oct 25, 2012

Fixed missing .id for reenabling the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment