How to reload a chrome extension automatically?

Viewed 6516

I am developing a chrome extension, and I found that there are repeating useless manual reloading works.

When you save a file, you have to refresh the chrome:\\extensions page to let browser to reload the extension. And then you have to reload the test page to see if the changes to files take effect.

I am newbie to Chrome extension development. And are there any ways to reduce the repeating works? I am also curious that what is the best practice of chrome extension development workflow.

Poor English, feel free to correct.

3 Answers

I built Clerc to work out-of-the-box with any LiveReload server. Just include any LiveReload compatible watcher in your build process and Clerc will take care of reloading.

I have to reveal this because it is little bit more boiled down for dummies (->miself) than gkalpak's solution but is based on that. This uses a plain bookmark to reload Chrome extension. As prerequisite an Apache is running at port 80.

  1. Create a bookmark at bookmark bar with real functioning localhost url: 'http://localhost/subdir/reload_dummy.php'. That php file was empty. You can change the url to be any valid url on the web to match your need.
  2. Add webRequest permission item to manifest.json:

    "permissions":[ "webRequest","tabs"],

Then copy some code to background.js:

var reloadURL = 'http://localhost/subdir/reload_dummy.php';
var cbBeforeRequest = function (info) {

    if (info.url === reloadURL) {
          chrome.runtime.reload();
           alert("HiiHaa!:" + info.url);
    }

}
var filters = {urls: [reloadURL]};
chrome.webRequest.onBeforeRequest.addListener(cbBeforeRequest, filters);
Related