(core) Fix breakage on Firefox iOS

Summary:
Grist recently stopped working on Firefox on iOS. The cause turns out an uncaught error, which is reported as an unhelpful "Script Error", but the act of reporting it causes additional errors, leading to an infinite loop and an unusable browser tab.

Firefox-iOS is to blame, but a workaround is preventing a flood of "Script Error" messages. Specifically, we report only the first of these, and only to the server, suppressing the user-visible toast.

Test Plan: Tested manually on Firefox on iOS. Added a test case, and improve other tests of uncaught errors.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3902
This commit is contained in:
Dmitry S
2023-05-22 15:55:20 -04:00
parent f18bb3e39d
commit d4bc6246f1
2 changed files with 36 additions and 3 deletions

View File

@@ -3068,6 +3068,19 @@ export async function assertIsRickRowing(expected: boolean) {
assert.equal(await driver.find('iframe#youtube-player-dQw4w9WgXcQ').isPresent(), expected);
}
export function produceUncaughtError(message: string) {
// Simply throwing an error from driver.executeScript() may produce a sanitized "Script error",
// depending on browser/webdriver version. This is a trick to ensure the uncaught error is
// considered same-origin by the main window.
return driver.executeScript((msg: string) => {
const script = document.createElement("script");
script.type = "text/javascript";
script.innerText = 'setTimeout(() => { throw new Error(' + JSON.stringify(msg) + '); }, 0)';
document.head.appendChild(script);
}, message);
}
} // end of namespace gristUtils
stackWrapOwnMethods(gristUtils);