FrankC
FrankC

Reputation: 11433

How to auto-update javascript in chrome extensions

I have a chrome extension which have a server-side javascript and I need this js to be reloaded every [1] hour on the client side. What´s the best way to do it?

Upvotes: 1

Views: 12848

Answers (2)

Rob W
Rob W

Reputation: 349042

Method 1
Bump your extension version every couple of hours. Chrome will automatically update the extension: http://code.google.com/chrome/extensions/autoupdate.html.

Method 2, distinguishing cases:

  • JSON: When the "server-side JS" only contains data, this is the best solution. Use setInterval in the background page to regularly update the variables. Do not forget to set the permissions in manifest.json, to enable cross-origin XHR.
    The response can be parsed with JSON.parse.
  • Script: Another option is to dynamically inject <script> tags in the background page.

Warning: Loading and executing external scripts in the background page poses a potential security hole in the extension.

When the network connection or your server is compromised, an evil third party can execute arbitrary code with your extension's privileges!

Upvotes: 3

Dmitrii Sorin
Dmitrii Sorin

Reputation: 4026

Ask your question in more clear way. As far as i understand you want to update the js-code on client-side every hour. If so, you can't do this in chrome extensions.

Upvotes: 1

Related Questions