0

Before the manifest change, the extension read a simple .js file written on my site every 5 minutes to tell what color to make the badge. It would change in response to alerts. This manifest has me flummoxed. The request:

<script type="text/javascript" src="alert.js"></script>

The background.html reads an external .js file. How?

mechanicalfish
  • 12,696
  • 3
  • 46
  • 41
  • What's in `alert.js`? Where are you getting the colour – megawac Nov 13 '13 at 01:00
  • Also the background page is literally a page, you can inject the script into `document.head` – megawac Nov 13 '13 at 01:00
  • Just a number. The script in the background says if 1 then color if 2 then color. From my under standing, they don't allow it with just a simple insert. –  Nov 13 '13 at 01:10
  • Why don't you have the actual path to your server in the `src` attribute ? What do you mean by "_it would change in response to alerts_" ? Post more code (manifest, background etc) or express your requirements in more detail. – gkalpak Nov 13 '13 at 06:03

1 Answers1

0

Can you not just poll your website and get the colour as a json/xml response? None the less, you should be able to just inject the script as you'd expect - just add it to the web-accessible-resources in manifest:

...
"web_accessible_resources": ["http://myserver.com/myscript.js"]
...

In background:

...

var s = document.createElement('script');
s.type = "text/javascript";
s.src = "http://myserver.com/myscript.js";
s.addEventListener('load', function (e) {

    /*
    work
    */

}, false);
document.head.appendChild(s);

...
megawac
  • 10,953
  • 5
  • 40
  • 61
  • Tried, no luck loading. Would it work better to load a var in the js? For example, in the .js is -> var alert=1; –  Nov 13 '13 at 01:44
  • Also, is the web_resources... in the "background" or on it's own? –  Nov 13 '13 at 01:46
  • I believe `web_accessible_resources` is for files **inside** your extension that need to be accessed from external web-pages (e.g. an image injected into a web-page). It won't have any effect here. – gkalpak Nov 13 '13 at 05:59