How do I auto-reload a Chrome extension I'm developing?

05/17/2020 15:00:01

I'd like for my chrome extension to reload every time I save a file in the extension folder, without having to explicitly click "reload" in chrome://extensions/. Is this possible?

Edit: I'm aware I can update the interval at which Chrome reloads extensions, which is a half-way solution, but I'd rather either making my editor (emacs or textmate) trigger on-save a reload or asking Chrome to monitor the directory for changes.

Verified Answer (160 Votes)

10/07/2012 13:18:27

You can use "Extensions Reloader" for Chrome:

Reloads all unpacked extensions using the extension's toolbar button or by browsing to "http://reload.extensions"

If you've ever developed a Chrome extension, you might have wanted to automate the process of reloading your unpacked extension without the need of going through the extensions page.

"Extensions Reloader" allows you to reload all unpacked extensions using 2 ways:

1 - The extension's toolbar button.

2 - Browsing to "http://reload.extensions".

The toolbar icon will reload unpacked extensions using a single click.

The "reload by browsing" is intended for automating the reload process using "post build" scripts - just add a browse to "http://reload.extensions" using Chrome to your script, and you'll have a refreshed Chrome window.

Update: As of January 14, 2015, the extension is open-sourced and available on GitHub.

160

Answer #2 (58 Votes)

03/10/2012 14:41:34

Update: I have added an options page, so that you don't have to manually find and edit the extension's ID any more. CRX and source code are at: https://github.com/Rob--W/Chrome-Extension-Reloader
Update 2: Added shortcut (see my repository on Github).
The original code, which includes the basic functionality is shown below.


Create an extension, and use the Browser Action method in conjunction with the chrome.extension.management API to reload your unpacked extension.

The code below adds a button to Chrome, which will reload an extension upon click.

manifest.json

{
    "name": "Chrome Extension Reloader",
    "version": "1.0",
    "manifest_version": 2,
    "background": {"scripts": ["bg.js"] },
    "browser_action": {
        "default_icon": "icon48.png",
        "default_title": "Reload extension"
    },
    "permissions": ["management"]
}

bg.js

var id = "<extension_id here>";
function reloadExtension(id) {
    chrome.management.setEnabled(id, false, function() {
        chrome.management.setEnabled(id, true);
    });
}
chrome.browserAction.onClicked.addListener(function(tab) {
    reloadExtension(id);
});

icon48.png: Pick any nice 48x48 icon, for example:
Google Chrome Google Chrome

58

Answer #3 (40 Votes)

05/23/2013 03:11:54

in any function or event

chrome.runtime.reload();

will reload your extension (docs). You also need to change the manifest.json file, adding:

...
"permissions": [ "management" , ...]
...
40
3
Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.