Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow Partytown to access window objects from main thread (#166)
- Loading branch information
1 parent
9203bbf
commit 9c1762b
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='UTF-8' /> | ||
<meta name='viewport' content='width=device-width, initial-scale=1' /> | ||
<meta name='description' content='Partytown Test Page' /> | ||
<title>Main Window Accessors</title> | ||
|
||
<script> | ||
partytown = { | ||
logCalls: true, | ||
logGetters: true, | ||
logSetters: true, | ||
logStackTraces: false, | ||
logScriptExecution: true, | ||
mainWindowAccessors: ['globalField'], | ||
}; | ||
</script> | ||
<script src='/~partytown/debug/partytown.js'></script> | ||
|
||
<script> | ||
window.globalField = { | ||
value: 42, | ||
parentObj: { | ||
childValue: 'stringValue', | ||
}, | ||
}; | ||
</script> | ||
|
||
<style> | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, | ||
Apple Color Emoji, Segoe UI Emoji; | ||
font-size: 12px; | ||
} | ||
|
||
h1 { | ||
margin: 0 0 15px 0; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
a { | ||
display: block; | ||
padding: 16px 8px; | ||
} | ||
|
||
a:link, | ||
a:visited { | ||
text-decoration: none; | ||
color: blue; | ||
} | ||
|
||
a:hover { | ||
background-color: #eee; | ||
} | ||
|
||
li { | ||
display: flex; | ||
margin: 15px 0; | ||
} | ||
|
||
li strong, | ||
li code, | ||
li button { | ||
white-space: nowrap; | ||
flex: 1; | ||
margin: 0 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Main Window Accessors</h1> | ||
<ul> | ||
<li> | ||
<strong>Parent level access</strong> | ||
<code id='testWindowAccessor'></code> | ||
<script type='text/partytown'> | ||
document.getElementById('testWindowAccessor').innerText = window.globalField.value; | ||
</script> | ||
</li> | ||
<li> | ||
<strong>Child level access</strong> | ||
<code id='testChildWindowAccessor'></code> | ||
<script type='text/partytown'> | ||
document.getElementById('testChildWindowAccessor').innerText = window.globalField.parentObj.childValue; | ||
</script> | ||
</li> | ||
<script type='text/partytown'> | ||
document.body.classList.add('completed'); | ||
</script> | ||
</ul> | ||
|
||
|
||
<hr /> | ||
<p><a href='/tests/'>All Tests</a></p> | ||
|
||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
tests/integrations/main-window-accessors/main-window-accessors.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.only('integration window accessor', async ({ page }) => { | ||
await page.goto('/tests/integrations/main-window-accessors/'); | ||
await page.waitForSelector('.completed'); | ||
|
||
const element = page.locator('#testWindowAccessor'); | ||
await expect(element).toHaveText('42'); | ||
|
||
const child_element = page.locator('#testChildWindowAccessor'); | ||
await expect(child_element).toHaveText('stringValue'); | ||
}); |
9c1762b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
partytown – ./
partytown-git-main-builder-io.vercel.app
partytown.vercel.app
partytown-builder-io.vercel.app
partytown.builder.io