Skip to content

Commit

Permalink
feat: window props
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 21, 2021
1 parent 93cc07c commit ccbb8ad
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/web-worker/worker-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export const createEnvironment = ({
const windowFunctionWhiteList =
'addEventListener,removeEventListener,dispatchEvent,postMessage'.split(',');

const windowPropertyWhiteList = 'onmessage,onload,onerror'.split(',');
const windowPropertyWhiteList =
'devicePixelRatio,innerHeight,innerWidth,onmessage,onload,onerror'.split(',');

const initWindowInstance = (win: any) => {
win[WinIdKey] = $winId$;
Expand Down
38 changes: 36 additions & 2 deletions tests/platform/window/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ <h1>Window</h1>
(function () {
const b = document.getElementById('testBtoa');
const a = document.getElementById('testAtob');
b.textContent = window.btoa('88');
a.textContent = atob(b.textContent);
const v1 = window.btoa('88');
const v2 = atob(v1);
b.textContent = v1;
a.textContent = v2;
})();
</script>
</li>
Expand Down Expand Up @@ -375,6 +377,38 @@ <h1>Window</h1>
</script>
</li>

<li>
<strong>innerWidth/Height</strong>
<code>
<span id="testInnerWidthHeight"></span>
</code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testInnerWidthHeight');
if (typeof window.innerWidth === 'number' && typeof window.innerWidth === 'number') {
elm.textContent = window.innerWidth + 'x' + window.innerHeight;
}
elm.className = 'testInnerWidthHeight';
})();
</script>
</li>

<li>
<strong>devicePixelRatio</strong>
<code>
<span id="testDevicePixelRatio"></span>
</code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testDevicePixelRatio');
if (typeof window.devicePixelRatio === 'number') {
elm.textContent = window.devicePixelRatio;
}
elm.className = 'testDevicePixelRatio';
})();
</script>
</li>

<script type="text/partytown">
(function () {
document.body.classList.add('completed');
Expand Down
6 changes: 6 additions & 0 deletions tests/platform/window/window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ test('window', async ({ page }) => {

const testFrameElement = page.locator('#testFrameElement');
await expect(testFrameElement).toHaveText('null');

const testInnerWidthHeight = page.locator('#testInnerWidthHeight');
await expect(testInnerWidthHeight).not.toHaveText('');

const testDevicePixelRatio = page.locator('#testDevicePixelRatio');
await expect(testDevicePixelRatio).not.toHaveText('');
});

1 comment on commit ccbb8ad

@vercel
Copy link

@vercel vercel bot commented on ccbb8ad Oct 21, 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.