From b16e649d531dd953e2d7b283a7ee316b7a3445ff Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Fri, 16 Aug 2024 03:42:19 +0300 Subject: [PATCH] added error message in case web worker cannot be started on web-app --- ng-app/index-web.html | 3 +++ ng-app/src/lib/Login.svelte | 1 + ng-app/src/locales/en.json | 3 ++- ng-app/src/routes/WalletCreate.svelte | 11 +++++++++++ ng-app/src/workertest.js | 1 + 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 ng-app/src/workertest.js diff --git a/ng-app/index-web.html b/ng-app/index-web.html index 0239b72..80f69de 100644 --- a/ng-app/index-web.html +++ b/ng-app/index-web.html @@ -118,12 +118,15 @@ const supported = (() => { if (RegExp().hasIndices === undefined) return false; try { + if (Worker === undefined) return false; + new Worker(URL.createObjectURL(new Blob(['console.log("webworker ok");'], {type: 'application/javascript'}))); if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") { const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); if (module instanceof WebAssembly.Module) return new WebAssembly.Instance(module) instanceof WebAssembly.Instance; } + } catch (e) { } return false; diff --git a/ng-app/src/lib/Login.svelte b/ng-app/src/lib/Login.svelte index 0e8bdcb..7411aee 100644 --- a/ng-app/src/lib/Login.svelte +++ b/ng-app/src/lib/Login.svelte @@ -258,6 +258,7 @@ } } catch (e) { console.error(e); + if (e.message.includes("constructor") || (typeof e === "string" && e.includes("constructor") )) e = "BrowserTooOld"; error = e; step = "end"; dispatch("error", { error: e }); diff --git a/ng-app/src/locales/en.json b/ng-app/src/locales/en.json index 37c0d96..44ce088 100644 --- a/ng-app/src/locales/en.json +++ b/ng-app/src/locales/en.json @@ -603,7 +603,8 @@ "WsError": "WebSocket error", "cannot_load_this_file": "Cannot load this file", "graph_not_found": "Graph not found", - "no_wasm_on_old_safari": "Your Safari browser is too old (version before 14.1). As a result we cannot load Automerge, needed for this document. Please upgrade your macOS or iOS system" + "no_wasm_on_old_safari": "Your Safari browser is too old (version before 14.1). As a result we cannot load Automerge, needed for this document. Please upgrade your macOS or iOS system", + "BrowserTooOld": "Your browser is too old. Please upgrade it, use another browser, or install our native app" }, "connectivity": { "stopped": "Stopped", diff --git a/ng-app/src/routes/WalletCreate.svelte b/ng-app/src/routes/WalletCreate.svelte index 76d3181..c34857f 100644 --- a/ng-app/src/routes/WalletCreate.svelte +++ b/ng-app/src/routes/WalletCreate.svelte @@ -173,6 +173,17 @@ async function bootstrap() { //console.log(await ng.client_info()); if (!tauri_platform || tauri_platform == "android") { + + if (!tauri_platform) { + try { + let worker_import = await import("../workertest.js?worker&inline"); + const myWorker = new worker_import.default(); + } catch (e) { + registration_error = "BrowserTooOld"; + return; + } + } + if (param.get("skipintro") || param.get("rs")) { intro = false; } diff --git a/ng-app/src/workertest.js b/ng-app/src/workertest.js new file mode 100644 index 0000000..021c582 --- /dev/null +++ b/ng-app/src/workertest.js @@ -0,0 +1 @@ +console.log("workertest ok"); \ No newline at end of file