How to Auto-Reload a Chrome Extension I'm Developing

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

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.

How to reload a chrome extension automatically?

The extension can reload itself, by calling chrome.runtime.reload(), so it's a matter of triggering the extension to do it.

One method that worked for me, is to watch for tabs' onUpdated event and look for a specific URL (you have come up with), e.g. http://localhost/reloadX?id=....

This is the sample code (to be placed in background.js):

var myReloadURL = 'http://localhost/reloadX?id='
+ chrome.i18n.getMessage('@@extension_id');

chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
if (info.url === myReloadURL) {
chrome.tabs.remove(tabId);
chrome.runtime.reload();
}
});

Additional permissions (to be declared in manifest.json):

...
"permissions": [
...
"tabs",
"http://localhost/reloadX?id=*"

myReloadURL is arbitrary and can be any URL, just doesn't have to be a real URL or the resource will be rendered unreachable.

Now, in order to reload your extension, you need to open the following address in Chrome:

http://localhost/reloadX?id=<your_extension_id>

It is up to you to choose how to trigger that on save. It could be an on-save hook in your editor, a custom grunt-watch task (since you seem to be familiar with grunt) etc .


(BTW, you don't need to reload the chrome://extensions page. It suffices to reload the extension.)

How do I refresh/reload a Chrome Extension?

The chrome.send function is not accessible by your extension's javascript code, pages like the newtab page, history and the extensions page use it to communicate with the C++ controller code for those pages.

You can push updates of your extension to users who have it installed, this is described here. The user's application will be updated once the autoupdate interval is hit or when they restart the browser. You cannot however reload a user's extension programmatically. I think that would be a security risk.

Auto-reload browser when I save changes to html file, in Chrome?

I assume you're not on OSX? Otherwise you could do something like this with applescript:

http://brettterpstra.com/watch-for-file-changes-and-refresh-your-browser-automatically/

There is also a plugin for chrome called "auto refresh plus" where you can specify a reload every x seconds:

https://chrome.google.com/webstore/detail/auto-refresh-plus-page-mo/hgeljhfekpckiiplhkigfehkdpldcggm?hl=en

chrome extension API for refreshing the page

I recommend using chrome.tabs.executeScript to inject javascript that calls window.location.reload() into the current tab. Something like:

chrome.tabs.getSelected(null, function(tab) {
var code = 'window.location.reload();';
chrome.tabs.executeScript(tab.id, {code: code});
});

Reference here



Related Topics



Leave a reply



Submit