Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I refresh/reload a Chrome Extension?

I'm developing an extension in Chrome 4 (currently 4.0.249.0) that will show the user's StackOverflow/SuperUser/ServerFault reputation in the status bar. I've designed an options page to get the user's profile IDs and I save them to localStorage and read them well in the extension. It all works great.
The problem is I cannot find a (programmatic) way to refresh the extension upon options saving. I tried calling location.reload(); from the extension page itself upon right clicking it - to no avail. I pursued it further and tried looking at what Chrome's chrome://extensions/ page does to reload an extension, and found this code:

/**
 * Handles a 'reload' button getting clicked.
 */
function handleReloadExtension(node) {
  // Tell the C++ ExtensionDOMHandler to reload the extension.
  chrome.send('reload', [node.extensionId]);
}

Copying this code to my event handler did not help (and yes, I tried replacing [node.extensionId] with the actual code). Can someone please assist me in doing this the right way, or pointing me at a code of an extension that does this correctly? Once done, I'll put the extension and its source up on my blog.

like image 456
Traveling Tech Guy Avatar asked Nov 19 '09 08:11

Traveling Tech Guy


People also ask

Is there an auto refresh for Chrome?

Click on the puzzle piece icon, then on “Easy Auto Refresh”. In the popup window, enter the number of seconds after which you want the page to refresh, then click “Start”. The page will automatically refresh every time the timer you set expires.

How do I auto refresh a web page?

It's as simple as going to your browser's app/extension store and finding one you like: Launch your browser. Go to app/extension store (Chrome Web Store, Firefox Add-Ons, Microsoft Edge Add-ons Store, etc.). Enter “auto-refresh” in the search bar.

How do you refresh an extension in Chrome?

Open the Google Chrome browser and make sure you can access the Deep Security Manager console. Click the three vertical dots on the upper-right corner and select Settings. Select Extensions and click Get more extensions at the bottom of the page. Search for the Auto Reload Page Extension and click Add to Chrome.


2 Answers

Now the simplest way to make extension to reload itself is to call chrome.runtime.reload(). This feature doesn't need any permissions in manifest. To reload another extension use chrome.management.setEnabled(). It requires "permissions": [ "management" ] in manifest.

like image 183
Konstantin Smolyanin Avatar answered Oct 06 '22 12:10

Konstantin Smolyanin


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.

like image 25
Pierre-Antoine LaFayette Avatar answered Oct 06 '22 12:10

Pierre-Antoine LaFayette