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,
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) {

View File

@ -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(() => {

View File

@ -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;
}