From e7eed805aac1d0130914b31668ea42c5ca1a79a0 Mon Sep 17 00:00:00 2001 From: GeorgiZhelev <30194786+GeorgiZhelev@users.noreply.github.com> Date: Thu, 7 Sep 2023 02:53:04 +0300 Subject: [PATCH] Partytown worker failing to initialize after passing non-serializable objects to postMessage (#458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/lib/sandbox/read-main-platform.ts | 5 +- tests/platform/klaviyo/current-script-src.js | 8 + tests/platform/klaviyo/document.spec.ts | 103 ++++ tests/platform/klaviyo/index.html | 479 +++++++++++++++++++ 4 files changed, 592 insertions(+), 3 deletions(-) create mode 100644 tests/platform/klaviyo/current-script-src.js create mode 100644 tests/platform/klaviyo/document.spec.ts create mode 100644 tests/platform/klaviyo/index.html diff --git a/src/lib/sandbox/read-main-platform.ts b/src/lib/sandbox/read-main-platform.ts index a61e3b25..7f59d95e 100644 --- a/src/lib/sandbox/read-main-platform.ts +++ b/src/lib/sandbox/read-main-platform.ts @@ -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) => { @@ -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') { diff --git a/tests/platform/klaviyo/current-script-src.js b/tests/platform/klaviyo/current-script-src.js new file mode 100644 index 00000000..de8cb7cf --- /dev/null +++ b/tests/platform/klaviyo/current-script-src.js @@ -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; diff --git a/tests/platform/klaviyo/document.spec.ts b/tests/platform/klaviyo/document.spec.ts new file mode 100644 index 00000000..92501917 --- /dev/null +++ b/tests/platform/klaviyo/document.spec.ts @@ -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`); +}); diff --git a/tests/platform/klaviyo/index.html b/tests/platform/klaviyo/index.html new file mode 100644 index 00000000..f57879d9 --- /dev/null +++ b/tests/platform/klaviyo/index.html @@ -0,0 +1,479 @@ + + + + + + + Document + + + + + + + +

Document

+ + +
+

All Tests

+ +