From 510a886e1445bcd5b2d72c01438a14a31cb230bd Mon Sep 17 00:00:00 2001 From: eight Date: Thu, 11 Oct 2018 03:21:38 +0800 Subject: [PATCH] Fix: exposeIframes --- background/background.js | 9 +++------ content/apply.js | 4 ++-- js/msg.js | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/background/background.js b/background/background.js index 9bcd2fe2..f2b7c3a1 100644 --- a/background/background.js +++ b/background/background.js @@ -14,9 +14,8 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, { installStyle: styleManager.installStyle, editSave: styleManager.editSave, - getTabDomain() { - return getTab(this.sender.tabId) - .then(tab => tab.url.match(/^[\w-]+:\/\/(?:[\w:-]+@)?([^:/#]+)/)[1]); + getTabUrlPrefix() { + return this.sender.tab.url.match(/^([\w-]+:\/\/[^/#]+)/)[1]; }, getStyleFromDB: id => @@ -100,9 +99,7 @@ navigatorUtil.onUrlChange(({tabId, frameId}, type) => { return; } msg.sendTab(tabId, {method: 'urlChanged'}, {frameId}) - .catch(err => { - console.warn(tabId, frameId, err); - }); + .catch(msg.broadcastError); }); if (FIREFOX) { diff --git a/content/apply.js b/content/apply.js index dd348256..fbb39e1f 100644 --- a/content/apply.js +++ b/content/apply.js @@ -171,14 +171,14 @@ if (parentDomain) { return Promise.resolve(); } - return API.getTabDomain() + return API.getTabUrlPrefix() .then(newDomain => { parentDomain = newDomain; }); } function updateExposeIframes() { - if (!prefs.get('exposeIframes') || window !== parent || !styleElements.size) { + if (!prefs.get('exposeIframes') || window === parent || !styleElements.size) { document.documentElement.removeAttribute('stylus-iframe'); } else { fetchParentDomain().then(() => { diff --git a/js/msg.js b/js/msg.js index afc6d66a..c0130398 100644 --- a/js/msg.js +++ b/js/msg.js @@ -34,6 +34,7 @@ const msg = (() => { broadcast, broadcastTab, broadcastExtension, + broadcastError, on, onTab, onExtension, @@ -211,8 +212,18 @@ const msg = (() => { } Promise.resolve(result) .then( - data => ({error: false, data}), - err => ({error: true, data: err.message || String(err)}) + data => ({ + error: false, + data + }), + err => ({ + error: true, + data: Object.assign({ + message: err.message || String(err), + // FIXME: do we want to pass the entire stack? + stack: err.stack + }, err) // this allows us to pass custom properties e.g. `err.index` + }) ) .then(function doResponse(responseMessage) { if (message.from === 'extension' && bg === undefined) { @@ -292,7 +303,7 @@ const msg = (() => { function unwrap() { if (result.error) { - throw new Error(result.data); + throw Object.assign(new Error(result.data.message), result.data); } return result.data; }