Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gtm scripts not working with loadScriptsOnMainThread by id #399

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/web-worker/worker-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const structureChangingMethodNames = /*#__PURE__*/ commaSplit(

/** setters that could change dimensions of elements */
export const dimensionChangingSetterNames = /*#__PURE__*/ commaSplit(
'className,width,height,hidden,innerHTML,innerText,textContent'
'className,width,height,hidden,innerHTML,innerText,textContent,text'
);

/** method calls that could change dimensions of elements */
Expand Down
1 change: 1 addition & 0 deletions src/lib/web-worker/worker-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const patchHTMLScriptElement = (WorkerHTMLScriptElement: any, env: WebWor
},

textContent: innerHTMLDescriptor,
text: innerHTMLDescriptor,

type: {
get() {
Expand Down
81 changes: 52 additions & 29 deletions tests/integrations/load-scripts-on-main-thread/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
logScriptExecution: true,
loadScriptsOnMainThread: [
`http://${location.host}/tests/integrations/load-scripts-on-main-thread/test-script.js`,
`inline-test-script`
`inline-test-script`,
`inline-text-test-script`
],
};
</script>
Expand Down Expand Up @@ -79,29 +80,29 @@
<body>
<h1>Load scripts on main thread 🎉</h1>
<ul>
<li>
<strong>Script Type:</strong>
<code id='testScriptType'></code>
<script type='text/partytown'>
(() => {
const scriptElement = document.getElementById('testScript');
const codeElement = document.getElementById('testScriptType');
codeElement.innerText = scriptElement.type;
})()
</script>
</li>
<li>
<strong>Script Source:</strong>
<code id='testScriptSource'></code>
<script type='text/partytown'>
(() => {
const scriptElement = document.getElementById('testScript');
const codeElement = document.getElementById('testScriptSource');
codeElement.innerText = scriptElement.src;
})()
</script>
<li>
<strong>Script Type:</strong>
<code id='testScriptType'></code>
<script type='text/partytown'>
(() => {
const scriptElement = document.getElementById('testScript');
const codeElement = document.getElementById('testScriptType');

codeElement.innerText = scriptElement.type;
})()
</script>
</li>
<li>
<strong>Script Source:</strong>
<code id='testScriptSource'></code>
<script type='text/partytown'>
(() => {
const scriptElement = document.getElementById('testScript');
const codeElement = document.getElementById('testScriptSource');

codeElement.innerText = scriptElement.src;
})()
</script>
</li>
<li>
<strong>Partytown Config:</strong>
Expand All @@ -127,17 +128,39 @@ <h1>Load scripts on main thread 🎉</h1>
script.type = "text/javascript";
script.id = "inline-test-script";
script.innerHTML = `
document.getElementById('testInlineScript');

const testEl = document.getElementById('testInlineScript');
testEl.className = 'testInlineScript';
testEl.innerHTML = globalVariable;
(function () {
const testEl = document.getElementById('testInlineScript');
testEl.className = 'testInlineScript';
testEl.innerHTML = globalVariable;
})();
`;

document.body.appendChild(script);
})();
</script>
</li>
<li>
<strong>Inline script with text</strong>
<code id="testInlineTextScript"></code>
<script type="text/javascript">const globalVariable2 = 12;</script>
<script type="text/partytown">
(function () {
const script = document.createElement('script');

script.type = "text/javascript";
script.id = "inline-text-test-script";

script.text = `
(function () {
const testEl = document.getElementById('testInlineTextScript');
testEl.className = 'testInlineTextScript';
testEl.innerHTML = globalVariable2;
})();
`;
document.body.appendChild(script);
})();
</script>
</li>
</ul>

<hr />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ test('integration window accessor', async ({ page }) => {
await page.waitForSelector('.testInlineScript');
const testInlineScript = page.locator('#testInlineScript');
await expect(testInlineScript).toHaveText('12');

await page.waitForSelector('.testInlineTextScript');
const testInlineTextScript = page.locator('#testInlineTextScript');
await expect(testInlineTextScript).toHaveText('12');
});