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 @@

Navigator

})(); +
  • + Properties defined in global navigator but not in the worker instance + + +

  • diff --git a/tests/platform/navigator/navigator.spec.ts b/tests/platform/navigator/navigator.spec.ts index e3df2815..87c6e856 100644 --- a/tests/platform/navigator/navigator.spec.ts +++ b/tests/platform/navigator/navigator.spec.ts @@ -14,4 +14,10 @@ test('navigator', async ({ page }) => { await page.waitForSelector('.testNavKey'); const testNavKey = page.locator('#testNavKey'); await expect(testNavKey).toContainText('5'); + + await page.waitForSelector('.testMainNavigatorProperties'); + const testMainNavigatorProperties = page.locator('#testMainNavigatorProperties'); + await expect(testMainNavigatorProperties).toContainText( + '{"javaEnabled":false,"cookieEnabled":true,"undefinedProp":"is_undefined","nullProp":null,"falseProp":false,"emptyStringProp":"","newProperty":"is_undefined","pdfViewerEnabled":"available","plugins":"available"}' + ); });