Skip to content

Commit

Permalink
fix: navigator (#381)
Browse files Browse the repository at this point in the history
Co-authored-by: vinay gosain <vinay.gosain@olx.com>
  • Loading branch information
vinaygosain and vinay gosain authored Mar 21, 2023
1 parent 32f9543 commit 65d2e24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/web-worker/worker-navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ export const createNavigator = (env: WebWorkerEnvironment) => {
nav[key] = (navigator as any)[key];
}

return nav;
return new Proxy(nav, {
set(_, propName, propValue) {
(navigator as any)[propName] = propValue;
return true;
},
});
};
12 changes: 12 additions & 0 deletions tests/platform/navigator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ <h1>Navigator</h1>
})();
</script>
</li>
<li>
<strong>Assign value 5 to navigator.a</strong>
<code id="testNavKey"></code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testNavKey');
navigator.a=5;
elm.textContent = navigator.a;
elm.className = 'testNavKey';
})();
</script>
</li>
</ul>

<hr />
Expand Down
6 changes: 5 additions & 1 deletion tests/platform/navigator/navigator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ test('navigator', async ({ page }) => {

const testUserAgent = await page.waitForSelector('.testUserAgent');
const ua = await testUserAgent.textContent();
expect(ua.startsWith('Mozilla/5.0')).toBe(true);
expect(ua?.startsWith('Mozilla/5.0')).toBe(true);

await page.waitForSelector('.testSendBeacon');
const testSendBeacon = page.locator('#testSendBeacon');
await expect(testSendBeacon).toContainText('true');

await page.waitForSelector('.testNavKey');
const testNavKey = page.locator('#testNavKey');
await expect(testNavKey).toContainText('5');
});

1 comment on commit 65d2e24

@vercel
Copy link

@vercel vercel bot commented on 65d2e24 Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.