Skip to content

Commit

Permalink
fix: createEnvironment in createHTMLDocument (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
quickshiftin committed Jun 1, 2022
1 parent 351a7a7 commit 9c0ef6f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/lib/web-worker/worker-document.ts
Expand Up @@ -178,11 +178,12 @@ export const patchDocument = (
callMethod(this, ['implementation', 'createHTMLDocument'], [title], CallType.Blocking, {
$winId$,
});
const docEnv = createWindow(
$winId$,
$winId$,
env.$location$ + '',
'hidden',
const docEnv = createEnvironment({
$winId$,
$parentWinId$: $winId$,
$url$: env.$location$ + '',
$visibilityState$: 'hidden',
},
true,
true
);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/web-worker/worker-environment.ts
Expand Up @@ -6,7 +6,7 @@ import { logWorker, normalizedWinId } from '../log';

export const createEnvironment = (
{ $winId$, $parentWinId$, $url$, $visibilityState$ }: InitializeEnvironmentData,
isIframeWindow?: boolean
isIframeWindow?: boolean, isDocumentImplementation?: boolean
) => {
if (!environments[$winId$]) {
// create a simulated global environment for this window
Expand All @@ -16,7 +16,8 @@ export const createEnvironment = (
$parentWinId$,
$url$,
$visibilityState$,
isIframeWindow
isIframeWindow,
isDocumentImplementation
);

if (debug) {
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/document/document.spec.ts
Expand Up @@ -92,7 +92,7 @@ test('document', async ({ page }) => {
await expect(testCreateElementError_).toHaveText('no error');

const testCreateHTMLDocument = page.locator('#testCreateHTMLDocument');
await expect(testCreateHTMLDocument).toHaveText('88mph hidden');
await expect(testCreateHTMLDocument).toHaveText('88mph hidden object');

const testVisibilityState = page.locator('#testVisibilityState');
await expect(testVisibilityState).toHaveText('visible');
Expand Down
6 changes: 5 additions & 1 deletion tests/platform/document/index.html
Expand Up @@ -432,9 +432,13 @@ <h1 class="title">Document</h1>
<script type="text/partytown">
(function () {
const doc = document.implementation.createHTMLDocument();
doc.body.textContent = '88mph ' + doc.visibilityState;

const elm = document.getElementById('testCreateHTMLDocument');

const addlElm = doc.createElement('base');
const addlElmType = typeof addlElm;

doc.body.textContent = '88mph ' + doc.visibilityState + ' ' + addlElmType;
elm.textContent = doc.body.textContent;
})();
</script>
Expand Down

1 comment on commit 9c0ef6f

@vercel
Copy link

@vercel vercel bot commented on 9c0ef6f Jun 1, 2022

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.