Skip to content

Commit

Permalink
window.screen
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 3, 2021
1 parent 87e80aa commit d364e48
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/web-worker/worker-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const initWebWorkerGlobal = (
self.document = constructInstance(InterfaceType.Document, PlatformInstanceId.document);
self.history = proxy(InterfaceType.History, self, ['history']);
self.localStorage = proxy(InterfaceType.Storage, self, ['localStorage']);
self.screen = proxy(InterfaceType.Object, self, ['screen']);
self.sessionStorage = proxy(InterfaceType.Storage, self, ['sessionStorage']);

navigator.sendBeacon = sendBeacon;
Expand Down
21 changes: 21 additions & 0 deletions tests/platform/window/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ <h1>Window</h1>
</script>
</li>

<li>
<strong>screen</strong>
<code>
<span id="testScreen"></span>
<span id="testScreenHasWidth"></span>
<span id="testScreenOrientation"></span>
</code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testScreen');
elm.textContent = `${screen.width}x${screen.height}`;
const elm2 = document.getElementById('testScreenHasWidth');
elm2.textContent = screen.width > 10;

const elm3 = document.getElementById('testScreenOrientation');
const orientation = screen.orientation;
elm3.textContent = (screen.orientation || {}).type;
})();
</script>
</li>

<script type="text/partytown">
(function () {
document.body.classList.add('completed');
Expand Down
3 changes: 3 additions & 0 deletions tests/platform/window/window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ test('window', async ({ page }) => {
const mainHTMLConstructors = page.locator('#mainHTMLConstructors');
const main = await mainHTMLConstructors.innerText();
expect(ww).toBe(main);

const testScreenHasWidth = page.locator('#testScreenHasWidth');
await expect(testScreenHasWidth).toHaveText('true');
});

1 comment on commit d364e48

@vercel
Copy link

@vercel vercel bot commented on d364e48 Oct 3, 2021

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.