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

Iframe Javascript URLs #122

Merged
merged 4 commits into from Mar 27, 2022

Conversation

montalvomiguelo
Copy link
Contributor

This MR allows us to execute scripts from Javascript URLs

@vercel
Copy link

vercel bot commented Mar 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/builder-io/partytown/J75Mt7U2yuPjQ8bptouywxPBqmPB
✅ Preview: https://partytown-git-fork-montalvomiguelo-iframe-js-in-urls-builder-io.vercel.app

Copy link
Contributor

@adamdbradley adamdbradley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job! Love the you added a test too. Only thing is to see about not using getter(), which will do a call to main. But if we have the src value already on the web worker we may be able to avoid that. Thanks

@@ -35,10 +35,18 @@ export const patchHTMLIFrameElement = (WorkerHTMLIFrameElement: any, env: WebWor

src: {
get() {
let src = getIframeEnv(this).$location$.href;
let src = getter(this, ['src']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do this without using getter() which is doing a call to the main thread? Could you try using getInstanceStateValue() and setInstanceStateValue() value instead so the value stays on the worker thread? The anchor element does something like this:

let value = getInstanceStateValue(this, StateProp.url);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that 🙏 I just used getInstanceStateValue() and setInstanceStateValue() to avoid calls to the main thread

@@ -69,6 +69,11 @@ export const createNodeCstr = (
if (isIFrame) {
// an iframe element's instanceId is also
// the winId of its contentWindow
const src = getter(newNode, ['src']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before, and try to avoid using getter()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getInstanceStateValue() now

src/lib/types.ts Outdated
@@ -524,6 +524,7 @@ export const enum NodeName {
export const enum StateProp {
errorHandlers = 'error',
loadHandlers = 'load',
src = 'src',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guy ok or should it be a number?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just updated it :)

Miguel Montalvo added 4 commits March 24, 2022 07:25
@adamdbradley
Copy link
Contributor

awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants