SHOW:
|
|
- or go back to the newest paste.
1 | // Test 1: Update manifest.json | |
2 | // Replace content_scripts with _content_scripts to see that | |
3 | // Changing the manifest file does not update the extension. | |
4 | // (or simply change the version number) | |
5 | ||
6 | // Test 2: Update contentscript.js | |
7 | // For example, replace alert with confirm. | |
8 | ||
9 | // manifest.json | |
10 | - | "js": ["script.js"] |
10 | + | |
11 | "name": "Reload test", | |
12 | "version": "1", | |
13 | "content_scripts": [{ | |
14 | "matches": ["<all_urls>"], | |
15 | - | // script.js |
15 | + | "js": ["contentscript.js"] |
16 | }], | |
17 | "background": {"scripts":["bg.js"]} | |
18 | } | |
19 | ||
20 | // contentscript.js | |
21 | alert('Test'); | |
22 | ||
23 | // bg.js | |
24 | function reloadOnChange(url, checkIntervalMS) { | |
25 | if (!window.__watchedFiles) { | |
26 | window.__watchedFiles = {}; | |
27 | } | |
28 | ||
29 | (function() { | |
30 | var self = arguments.callee; | |
31 | var xhr = new XMLHttpRequest(); | |
32 | ||
33 | xhr.onreadystatechange = function() { | |
34 | if (xhr.readyState == 4) { | |
35 | if (__watchedFiles[url] && | |
36 | __watchedFiles[url] != xhr.responseText) { | |
37 | window.location.reload(); | |
38 | } else { | |
39 | __watchedFiles[url] = xhr.responseText | |
40 | window.setTimeout(self, checkIntervalMS || 1000); | |
41 | } | |
42 | } | |
43 | }; | |
44 | - | console.log('loaded') |
44 | + | |
45 | - | reloadOnChange(chrome.extension.getURL('/manifest.json')); |
45 | + | |
46 | xhr.send(); | |
47 | })(); | |
48 | } | |
49 | reloadOnChange(chrome.extension.getURL('/manifest.json')); | |
50 | reloadOnChange(chrome.extension.getURL('/contentscript.js')); |