diff --git a/README.md b/README.md index 43d4ae6..fc2c2ae 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ Here's [a blog post explaining it](https://60devs.com/hot-reloading-for-chrome-e 2. Put the following into your `manifest.json` file: ```json - "background": { "scripts": ["hot-reload.js"] }, - "permissions": ["http://*/*", "https://*/*"], + "background": { "scripts": ["hot-reload.js"] } ``` Also, you can simply clone this repository and use it as a boilerplate for your extension. diff --git a/hot-reload.js b/hot-reload.js index 6eb9594..7183886 100644 --- a/hot-reload.js +++ b/hot-reload.js @@ -14,30 +14,12 @@ const timestampForFilesInDirectory = dir => filesInDirectory (dir).then (files => files.map (f => f.name + f.lastModifiedDate).join ()) -const reload = () => { - chrome.permissions.contains ({ - origins: ["http://*/*", "https://*/*"] - }, granted => { - if (granted) { - chrome.tabs.query ({ active: true, lastFocusedWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5 - if (tabs[0]) { - chrome.tabs.executeScript (tabs[0].id, { code: 'setTimeout(() => { location.reload() }, 300)' }, () => {}) - chrome.runtime.reload () - } - }) - } else { - alert ('Unable to reload the active tab — please add "http://*/*" and "https://*/*" permissions to manifest.json!') - chrome.runtime.reload () - } - }) -} - const watchChanges = (dir, lastTimestamp) => { timestampForFilesInDirectory (dir).then (timestamp => { if (!lastTimestamp || (lastTimestamp === timestamp)) { setTimeout (() => watchChanges (dir, timestamp), 1000) // retry after 1s } else { - reload () + chrome.runtime.reload () } }) } @@ -45,5 +27,10 @@ const watchChanges = (dir, lastTimestamp) => { chrome.management.getSelf (self => { if (self.installType === 'development') { chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir)) + chrome.tabs.query ({ active: true, lastFocusedWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5 + if (tabs[0]) { + chrome.tabs.reload (tabs[0].id) + } + }) } }) diff --git a/manifest.json b/manifest.json index f050a22..31e2bda 100644 --- a/manifest.json +++ b/manifest.json @@ -5,8 +5,6 @@ "description": "An example extension which demonstrates hot-reloading", "version": "1.1337.0", - "permissions": ["http://*/*", "https://*/*"], - "background": { "scripts": ["hot-reload.js"] }