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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
scriptContent = await rsp.text(); | ||
env.$currentScriptId$ = instanceId; | ||
run(env, scriptContent, scriptOrgSrc || scriptSrc); | ||
} | ||
runStateLoadHandlers(instance!, StateProp.loadHandlers); |
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.
Not entirely sure if this state change should be called or not
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. |
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? |
src/lib/web-worker/worker-exec.ts
Outdated
@@ -27,7 +27,8 @@ export const initNextScriptsInWebWorker = async (initScript: InitializeScriptDat | |||
let errorMsg = ''; | |||
let env = environments[winId]; | |||
let rsp: Response; | |||
|
|||
let contentTypeBlocklist = ["image/gif"] |
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.
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?
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.
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 :)
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.
Done
src/lib/web-worker/worker-exec.ts
Outdated
env.$currentScriptId$ = instanceId; | ||
run(env, scriptContent, scriptOrgSrc || scriptSrc); | ||
let responseContentType = rsp.headers.get("content-type") | ||
if (!contentTypeBlocklist.some(ct => ct === responseContentType)){ |
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.
This is a good idea, but rather should go with a whitelist instead of blacklist.
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.
Done
Finished the fixes and added end to end test @adamdbradley |
This is great, thanks so much for fixing this up! |
Summary
Fixes an issue where partytown prints an error when a third party scripts requests a resource different from a script.
Closes #245