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: Avoids converting a gif into a function #247

Merged
merged 6 commits into from Sep 23, 2022

Conversation

leocwolter
Copy link
Contributor

@leocwolter leocwolter commented Aug 25, 2022

Summary

Fixes an issue where partytown prints an error when a third party scripts requests a resource different from a script.

Closes #245

@vercel
Copy link

vercel bot commented Aug 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
partytown ✅ Ready (Inspect) Visit Preview Aug 29, 2022 at 7:29PM (UTC)

scriptContent = await rsp.text();
env.$currentScriptId$ = instanceId;
run(env, scriptContent, scriptOrgSrc || scriptSrc);
}
runStateLoadHandlers(instance!, StateProp.loadHandlers);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not entirely sure if this state change should be called or not

@leocwolter
Copy link
Contributor Author

Open for ideas about how to test that since the expected behaviour is that a gif is requested with no other side effects. Is there a way to verify that using playwright? 😅

Also, the integration that made us find that error was Google Adsense but that should happen everytime a script inside partytown requests something other than other script.
Considering that, is it acceptable to make a test simulating that behaviour instead of trying to replicate using Google Adsense?

@leocwolter leocwolter changed the title [ELO-8077] Avoids converting a gif as a function fix: Avoids converting a gif as a function Aug 25, 2022
@leocwolter leocwolter changed the title fix: Avoids converting a gif as a function fix: Avoids converting a gif into a function Aug 25, 2022
@adamdbradley
Copy link
Contributor

This looks like a good fix, but what you also be able to add some tests to this to ensure it continues to work, and isn't breaking other tests?

@@ -27,7 +27,8 @@ export const initNextScriptsInWebWorker = async (initScript: InitializeScriptDat
let errorMsg = '';
let env = environments[winId];
let rsp: Response;

let contentTypeBlocklist = ["image/gif"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a good idea to validate that's javascript before we execute it. But could we do the opposite here, where we have a whitelist of content types which are valid javascript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern with using a whitelist was that maybe some request doesnt return the correct contentType even though they are actually javascripts. If that is not something that you guys think could happen I can implement it as a white list :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

env.$currentScriptId$ = instanceId;
run(env, scriptContent, scriptOrgSrc || scriptSrc);
let responseContentType = rsp.headers.get("content-type")
if (!contentTypeBlocklist.some(ct => ct === responseContentType)){
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good idea, but rather should go with a whitelist instead of blacklist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@leocwolter
Copy link
Contributor Author

Finished the fixes and added end to end test @adamdbradley

@adamdbradley
Copy link
Contributor

This is great, thanks so much for fixing this up!

@leocwolter leocwolter deleted the ELO-8077 branch September 12, 2023 12:37
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.

Partytown tries to turn an image/gif response into a function
2 participants