From e7a4b6dbb77f13a7566e1f88a8949418fa70c49a Mon Sep 17 00:00:00 2001 From: Vitalik Gordon Date: Wed, 9 Dec 2020 09:02:20 +0300 Subject: [PATCH] fixes for #17 --- hot-reload.js | 17 +++-------------- manifest.json | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/hot-reload.js b/hot-reload.js index 577689a..6eb9594 100644 --- a/hot-reload.js +++ b/hot-reload.js @@ -1,9 +1,6 @@ const filesInDirectory = dir => new Promise (resolve => - dir.createReader ().readEntries (entries => - Promise.all (entries.filter (e => e.name[0] !== '.').map (e => - e.isDirectory ? filesInDirectory (e) : new Promise (resolve => e.file (resolve)) @@ -19,7 +16,7 @@ const timestampForFilesInDirectory = dir => const reload = () => { chrome.permissions.contains ({ - permissions: ["activeTab"] + origins: ["http://*/*", "https://*/*"] }, granted => { if (granted) { chrome.tabs.query ({ active: true, lastFocusedWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5 @@ -29,32 +26,24 @@ const reload = () => { } }) } else { - alert ('Unable to reload the active tab — please add the "activeTab" permission to manifest.json!') + 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.management.getSelf (self => { - if (self.installType === 'development') { - chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir)) } }) diff --git a/manifest.json b/manifest.json index 125182f..f050a22 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": "An example extension which demonstrates hot-reloading", "version": "1.1337.0", - "permissions": ["activeTab"], + "permissions": ["http://*/*", "https://*/*"], "background": { "scripts": ["hot-reload.js"]