diff --git a/background/usercss-helper.js b/background/usercss-helper.js index 8f46ac7e..4d5a4be9 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -85,7 +85,8 @@ var usercssHelper = (() => { return wrapReject(openURL({ url: '/install-usercss.html' + '?updateUrl=' + encodeURIComponent(url) + - '&tabId=' + (direct ? -tab.id : tab.id), + '&tabId=' + tab.id + + (direct ? '&direct=yes' : ''), index: tab.index + 1, openerTabId: tab.id, })); diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index d1abbf74..ede62830 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -10,7 +10,7 @@ const tabId = Number(params.get('tabId')); let port; - if (tabId < 0) { + if (params.has('direct')) { $('.live-reload').remove(); getCodeDirectly(); } else { @@ -327,7 +327,7 @@ function getCodeDirectly() { // FF applies page CSP even to content scripts, https://bugzil.la/1267027 // To circumvent that, the bg process downloads the code directly - const key = 'tempUsercssCode' + (-tabId); + const key = 'tempUsercssCode' + tabId; chrome.storage.local.get(key, data => { const code = data && data[key]; diff --git a/js/messaging.js b/js/messaging.js index e597a95c..3ac431be 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -128,7 +128,7 @@ function notifyAllTabs(msg) { } // notify background page and all open popups if (affectsSelf) { - msg.tabId = null; + msg.tabId = undefined; sendMessage(msg, ignoreChromeError); } } @@ -144,8 +144,8 @@ function sendMessage(msg, callback) { - enabled by passing a second param */ const {tabId, frameId} = msg; - const fn = tabId ? chrome.tabs.sendMessage : chrome.runtime.sendMessage; - const args = tabId ? [tabId, msg, {frameId}] : [msg]; + const fn = tabId >= 0 ? chrome.tabs.sendMessage : chrome.runtime.sendMessage; + const args = tabId >= 0 ? [tabId, msg, {frameId}] : [msg]; if (callback) { fn(...args, callback); } else {