Skip to content

Commit

Permalink
chore: try catch sjcl init error on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Mar 19, 2024
1 parent be06a14 commit c521030
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions assets/preload/streamChunksPreloadScript.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
* Delay the script execution slightly, until MutationObserver found document.body is ready.
*/
function executeScriptsAfterInjectHTML() {
var _a;
console.log('executeScriptsAfterInjectHTML');
try {
// load tiddlers store, place it after <div id="styleArea"> where it used to belong to.
Expand All @@ -113,8 +112,8 @@
var newScript = document.createElement('script');
// copy all attributes from the original script to the new one
var scriptTagAttributes = Array.from(script.attributes);
for (var _b = 0, scriptTagAttributes_1 = scriptTagAttributes; _b < scriptTagAttributes_1.length; _b++) {
var _c = scriptTagAttributes_1[_b], name_1 = _c.name, value = _c.value;
for (var _a = 0, scriptTagAttributes_1 = scriptTagAttributes; _a < scriptTagAttributes_1.length; _a++) {
var _b = scriptTagAttributes_1[_a], name_1 = _b.name, value = _b.value;
newScript.setAttribute(name_1, value);
}
if (script.src) {
Expand All @@ -126,7 +125,14 @@
newScript.textContent = script.textContent;
}
// replace the old script element with the new one
(_a = script.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(newScript, script);
if (script.parentNode !== null) {
try {
script.parentNode.replaceChild(newScript, script);
}
catch (error) {
console.error("Faile to refresh script tag with error ".concat(error.message, ": newScript, script"), newScript, script, error);
}
}
}
}
catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ export enum OnStreamChunksToWebViewEventTypes {
newScript.textContent = script.textContent;
}
// replace the old script element with the new one
script.parentNode?.replaceChild(newScript, script);
if (script.parentNode !== null) {
try {
script.parentNode.replaceChild(newScript, script);
} catch (error) {
// FIXME: can't catch error `SyntaxError: Can't create duplicate variable: 'A'` on iOS
console.error(`Faile to refresh script tag with error ${(error as Error).message}: newScript, script`, newScript, script, error);
}
}
}
} catch (error) {
console.error('executeScriptsAfterInjectHTML error', error);
Expand Down

0 comments on commit c521030

Please sign in to comment.