From 486b5a9df92dad22137bd0e07b8deeb6f9c2e8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20P=C3=A9rez=20Zamora?= <85033117+franpeza@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:20:18 +0100 Subject: [PATCH] feat: access missing navigator properties (#539) --- src/lib/web-worker/worker-navigator.ts | 13 ++++++++--- tests/platform/navigator/index.html | 25 ++++++++++++++++++++++ tests/platform/navigator/navigator.spec.ts | 6 ++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/lib/web-worker/worker-navigator.ts b/src/lib/web-worker/worker-navigator.ts index 3e1362e9..95e0e252 100644 --- a/src/lib/web-worker/worker-navigator.ts +++ b/src/lib/web-worker/worker-navigator.ts @@ -3,10 +3,10 @@ import { debug } from '../utils'; import { logWorker } from '../log'; import { resolveUrl } from './worker-exec'; import { webWorkerCtx } from './worker-constants'; +import { getter } from './worker-proxy'; export const createNavigator = (env: WebWorkerEnvironment) => { - let key: any; - let nav: any = { + const nav: any = { sendBeacon: (url: string, body?: any) => { if (debug && webWorkerCtx.$config$.logSendBeaconRequests) { try { @@ -34,7 +34,7 @@ export const createNavigator = (env: WebWorkerEnvironment) => { }, }; - for (key in navigator) { + for (let key in navigator) { nav[key] = (navigator as any)[key]; } @@ -43,5 +43,12 @@ export const createNavigator = (env: WebWorkerEnvironment) => { (navigator as any)[propName] = propValue; return true; }, + get(target, prop) { + if (Object.prototype.hasOwnProperty.call(target, prop)) { + return target[prop]; + } + const value = getter(env.$window$, ['navigator', prop]); + return value; + }, }); }; diff --git a/tests/platform/navigator/index.html b/tests/platform/navigator/index.html index a3920dbf..d69d362a 100644 --- a/tests/platform/navigator/index.html +++ b/tests/platform/navigator/index.html @@ -95,6 +95,31 @@
+
+