Fix: exposeIframes

This commit is contained in:
eight 2018-10-11 03:21:38 +08:00
parent c7f81662c4
commit 510a886e14
3 changed files with 19 additions and 11 deletions

View File

@ -14,9 +14,8 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
installStyle: styleManager.installStyle, installStyle: styleManager.installStyle,
editSave: styleManager.editSave, editSave: styleManager.editSave,
getTabDomain() { getTabUrlPrefix() {
return getTab(this.sender.tabId) return this.sender.tab.url.match(/^([\w-]+:\/\/[^/#]+)/)[1];
.then(tab => tab.url.match(/^[\w-]+:\/\/(?:[\w:-]+@)?([^:/#]+)/)[1]);
}, },
getStyleFromDB: id => getStyleFromDB: id =>
@ -100,9 +99,7 @@ navigatorUtil.onUrlChange(({tabId, frameId}, type) => {
return; return;
} }
msg.sendTab(tabId, {method: 'urlChanged'}, {frameId}) msg.sendTab(tabId, {method: 'urlChanged'}, {frameId})
.catch(err => { .catch(msg.broadcastError);
console.warn(tabId, frameId, err);
});
}); });
if (FIREFOX) { if (FIREFOX) {

View File

@ -171,14 +171,14 @@
if (parentDomain) { if (parentDomain) {
return Promise.resolve(); return Promise.resolve();
} }
return API.getTabDomain() return API.getTabUrlPrefix()
.then(newDomain => { .then(newDomain => {
parentDomain = newDomain; parentDomain = newDomain;
}); });
} }
function updateExposeIframes() { function updateExposeIframes() {
if (!prefs.get('exposeIframes') || window !== parent || !styleElements.size) { if (!prefs.get('exposeIframes') || window === parent || !styleElements.size) {
document.documentElement.removeAttribute('stylus-iframe'); document.documentElement.removeAttribute('stylus-iframe');
} else { } else {
fetchParentDomain().then(() => { fetchParentDomain().then(() => {

View File

@ -34,6 +34,7 @@ const msg = (() => {
broadcast, broadcast,
broadcastTab, broadcastTab,
broadcastExtension, broadcastExtension,
broadcastError,
on, on,
onTab, onTab,
onExtension, onExtension,
@ -211,8 +212,18 @@ const msg = (() => {
} }
Promise.resolve(result) Promise.resolve(result)
.then( .then(
data => ({error: false, data}), data => ({
err => ({error: true, data: err.message || String(err)}) 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) { .then(function doResponse(responseMessage) {
if (message.from === 'extension' && bg === undefined) { if (message.from === 'extension' && bg === undefined) {
@ -292,7 +303,7 @@ const msg = (() => {
function unwrap() { function unwrap() {
if (result.error) { if (result.error) {
throw new Error(result.data); throw Object.assign(new Error(result.data.message), result.data);
} }
return result.data; return result.data;
} }