diff --git a/internal/gui/pagebridge.js b/internal/gui/pagebridge.js index b215baa3b..49b73ade3 100644 --- a/internal/gui/pagebridge.js +++ b/internal/gui/pagebridge.js @@ -101,7 +101,8 @@ // reach its error handlers are not that: a script the browser put in // the frame (a wallet's or a translator's extension, whose stack names // chrome-extension://…), and a read of the window or another frame the - // sandbox shuts out ("Blocked a frame with origin "null" from accessing + // sandbox shuts out (its storage, "The document is sandboxed and lacks the + // 'allow-same-origin' flag"; "Blocked a frame with origin "null" from accessing // a cross-origin frame" in Chromium, "Sandbox access violation" in // WebKit; a SecurityError). The page goes on without // either, and the window's "stopped working" over it was a page that @@ -109,7 +110,13 @@ function foreign(err, file) { const where = String(file || "") + "\n" + String(err?.stack || ""); if (/(?:chrome|moz|safari-web)-extension:\/\//i.test(where)) return true; - return err?.name === "SecurityError" && /Blocked a frame (?:with origin|at )/.test(String(err?.message)); + // storage the sandbox has none of: "Failed to read the 'localStorage' + // property from 'Window': The document is sandboxed and lacks the + // 'allow-same-origin' flag" (Chromium; WebKit says "The operation is + // insecure"), read by a script that isn't the page's (nivekxft on X) + const why = String(err?.message); + if (err?.name === "SecurityError" && (/The operation is insecure/.test(why) || (/(?:local|session)Storage|\bstorage\b|cookie/i.test(why) && /sandboxed|allow-same-origin/i.test(why)))) return true; + return err?.name === "SecurityError" && /Blocked a frame (?:with origin|at )/.test(why); } function report(err) { parent.postMessage({ magpie: 1, method: "error", params: { message: String(err?.message || err) } }, "*"); diff --git a/internal/gui/tests/plugin-page-foreign-error.test.cjs b/internal/gui/tests/plugin-page-foreign-error.test.cjs index e0895461e..eb2e76004 100644 --- a/internal/gui/tests/plugin-page-foreign-error.test.cjs +++ b/internal/gui/tests/plugin-page-foreign-error.test.cjs @@ -26,6 +26,10 @@ const CASES = { rejected: { c: "c", broken: false, js: `Promise.resolve().then(() => parent.location.origin);` }, extension: { masked: true, c: "d", broken: false, js: `setTimeout(() => { const e = new Error("inpage"); e.stack = "Error: inpage\\n at chrome-extension://abcdef/inpage.js:1:1"; throw e; });` }, extensionRejected: { c: "e", broken: false, js: `{ const e = new Error("inpage"); e.stack = "Error: inpage\\n at moz-extension://abcdef/inpage.js:1:1"; Promise.reject(e); }` }, + // the storage the sandbox has none of (nivekxft: "Failed to read the + // 'localStorage' property from 'Window': The document is sandboxed ...") + storage: { masked: true, c: "1", broken: false, js: `setTimeout(() => { void localStorage.length; });` }, + storageRejected: { c: "2", broken: false, js: `Promise.resolve().then(() => sessionStorage.getItem("x"));` }, // the page's own mistakes still break it own: { masked: true, c: "f", broken: true, js: `setTimeout(() => { throw new Error("the page's own bug"); });` }, ownRejected: { c: "0", broken: true, js: `Promise.reject(new Error("the page's own bug"));` },