0 is a valid tab id

This commit is contained in:
tophf 2017-11-25 20:24:15 +03:00
parent ea277bcf4c
commit 6aef6cdcd7
3 changed files with 7 additions and 6 deletions

View File

@ -85,7 +85,8 @@ var usercssHelper = (() => {
return wrapReject(openURL({ return wrapReject(openURL({
url: '/install-usercss.html' + url: '/install-usercss.html' +
'?updateUrl=' + encodeURIComponent(url) + '?updateUrl=' + encodeURIComponent(url) +
'&tabId=' + (direct ? -tab.id : tab.id), '&tabId=' + tab.id +
(direct ? '&direct=yes' : ''),
index: tab.index + 1, index: tab.index + 1,
openerTabId: tab.id, openerTabId: tab.id,
})); }));

View File

@ -10,7 +10,7 @@
const tabId = Number(params.get('tabId')); const tabId = Number(params.get('tabId'));
let port; let port;
if (tabId < 0) { if (params.has('direct')) {
$('.live-reload').remove(); $('.live-reload').remove();
getCodeDirectly(); getCodeDirectly();
} else { } else {
@ -327,7 +327,7 @@
function getCodeDirectly() { function getCodeDirectly() {
// FF applies page CSP even to content scripts, https://bugzil.la/1267027 // FF applies page CSP even to content scripts, https://bugzil.la/1267027
// To circumvent that, the bg process downloads the code directly // To circumvent that, the bg process downloads the code directly
const key = 'tempUsercssCode' + (-tabId); const key = 'tempUsercssCode' + tabId;
chrome.storage.local.get(key, data => { chrome.storage.local.get(key, data => {
const code = data && data[key]; const code = data && data[key];

View File

@ -128,7 +128,7 @@ function notifyAllTabs(msg) {
} }
// notify background page and all open popups // notify background page and all open popups
if (affectsSelf) { if (affectsSelf) {
msg.tabId = null; msg.tabId = undefined;
sendMessage(msg, ignoreChromeError); sendMessage(msg, ignoreChromeError);
} }
} }
@ -144,8 +144,8 @@ function sendMessage(msg, callback) {
- enabled by passing a second param - enabled by passing a second param
*/ */
const {tabId, frameId} = msg; const {tabId, frameId} = msg;
const fn = tabId ? chrome.tabs.sendMessage : chrome.runtime.sendMessage; const fn = tabId >= 0 ? chrome.tabs.sendMessage : chrome.runtime.sendMessage;
const args = tabId ? [tabId, msg, {frameId}] : [msg]; const args = tabId >= 0 ? [tabId, msg, {frameId}] : [msg];
if (callback) { if (callback) {
fn(...args, callback); fn(...args, callback);
} else { } else {