Skip to content

Commit

Permalink
Partytown worker failing to initialize after passing non-serializable…
Browse files Browse the repository at this point in the history
… objects to postMessage (#458)

* add failing test case with Klaviyo base script tag

* add filtering for non-serializable interfaces and main data request log

* make objects serializable (not a fix)

* fix: missing  constructor

* fix: picking up klaviyo object

* fix: revert debug changes from GeorgiZhelev

---------

Co-authored-by: Miško Hevery <[email protected]>
  • Loading branch information
GeorgiZhelev and mhevery authored Sep 6, 2023
1 parent 3e8b049 commit e7eed80
Show file tree
Hide file tree
Showing 4 changed files with 592 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/lib/sandbox/read-main-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ export const readMainInterfaces = () => {
return readImplementations(elms, []);
};

const cstrs = new Set(['Object']);

const readImplementations = (impls: any[], interfaces: InterfaceInfo[]) => {
const cstrs = new Set(['Object']);
const cstrImpls = impls
.filter((implData) => implData[0])
.map((implData) => {
Expand Down Expand Up @@ -176,7 +175,7 @@ const readImplementationMember = (
}
} else if (memberType === 'object' && value != null) {
cstrName = getConstructorName(value);
if (cstrName !== 'Object' && (self as any)[cstrName]) {
if (cstrName !== 'Object' && cstrName !== 'Function' && (self as any)[cstrName]) {
interfaceMembers.push([memberName, value.nodeType || cstrName]);
}
} else if (memberType !== 'symbol') {
Expand Down
8 changes: 8 additions & 0 deletions tests/platform/klaviyo/current-script-src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const elm = document.getElementById('testCurrentScriptSrc');
elm.textContent = document.currentScript.dataset.currentScript;

const loc = document.getElementById('testCurrentScriptSrcLocation');

const currentScript = document.currentScript;
const currentUrl = new URL(currentScript.src);
loc.textContent = currentUrl.pathname;
103 changes: 103 additions & 0 deletions tests/platform/klaviyo/document.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { test, expect } from '@playwright/test';

test('document', async ({ page }) => {
await page.goto('/tests/platform/document/');

await page.waitForSelector('.completed');

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

const testGetElementsByTagName = page.locator('#testGetElementsByTagName');
await expect(testGetElementsByTagName).toHaveText('Document');

const testGetElementsByTagNameHead = page.locator('#testGetElementsByTagNameHead');
await expect(testGetElementsByTagNameHead).toHaveText('[HEAD]');

const testGetElementsByClassName = page.locator('#testGetElementsByClassName');
await expect(testGetElementsByClassName).toHaveText('Document');

const testTitleGet = page.locator('#testTitleGet');
await expect(testTitleGet).toHaveText('Document');

const testTitleSet = page.locator('#testTitleSet');
await expect(testTitleSet).toHaveText('Document!!!');

const testCookie = page.locator('#testCookie');
await expect(testCookie).toHaveText('mph=88');

const testLocationGet = page.locator('#testLocationGet');
await expect(testLocationGet).toHaveText('/tests/platform/document/');

const testDefaultView = page.locator('#testDefaultView');
await expect(testDefaultView).toHaveText('window');

const testDocElement = page.locator('#testDocElement');
await expect(testDocElement).toHaveText('HTML HTMLHtmlElement');

const testHead = page.locator('#testHead');
await expect(testHead).toHaveText('HEAD HTMLHeadElement');

const testBody = page.locator('#testBody');
await expect(testBody).toHaveText('BODY HTMLBodyElement');

const testCompatMode = page.locator('#testCompatMode');
await expect(testCompatMode).toHaveText('CSS1Compat');

const testCurrentScript = page.locator('#testCurrentScript');
await expect(testCurrentScript).toHaveText('inlined');

const testCurrentScriptSrc = page.locator('#testCurrentScriptSrc');
const testCurrentScriptSrcLocation = page.locator('#testCurrentScriptSrcLocation');
await expect(testCurrentScriptSrc).toHaveText('src');
await expect(testCurrentScriptSrcLocation).toHaveText(
'/tests/platform/document/current-script-src.js'
);

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

const testHeadParentNode = page.locator('#testHeadParentNode');
await expect(testHeadParentNode).toHaveText('HTML HTML');

const testBodyParentNode = page.locator('#testBodyParentNode');
await expect(testBodyParentNode).toHaveText('HTML HTML');

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

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

const testDocumentChildNodes = page.locator('#testDocumentChildNodes');
await expect(testDocumentChildNodes).toHaveText('2 [html(10), HTML(1)]');

const testDocumentForms = page.locator('#testDocumentForms');
await expect(testDocumentForms).toHaveText('0');

const testDocType = page.locator('#testDocType');
await expect(testDocType).toHaveText('10 html html false');

const testDocCstrName = page.locator('#testDocCstrName');
await expect(testDocCstrName).toHaveText('HTMLDocument');

const testReadyState = page.locator('#testReadyState');
await expect(testReadyState).toHaveText('complete');

const testCreateElementError = page.locator('#testCreateElementError');
await expect(testCreateElementError).toHaveText('errored');

const testCreateElementError_ = page.locator('#testCreateElementError_');
await expect(testCreateElementError_).toHaveText('no error');

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

const testVisibilityState = page.locator('#testVisibilityState');
await expect(testVisibilityState).toHaveText('visible');

const testImages = page.locator('#testDocumentImages');
const pageUrl = new URL(page.url());
await expect(testImages).toHaveText(`${pageUrl.origin}/fake.jpg`);
});
Loading

1 comment on commit e7eed80

@vercel
Copy link

@vercel vercel bot commented on e7eed80 Sep 7, 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.