fix: prevent iframe expansion failure on pages with Trusted Types CSP#3590
Merged
nikitachapovskii-dev merged 2 commits intomasterfrom Apr 22, 2026
Merged
Conversation
barjin
approved these changes
Apr 22, 2026
Member
barjin
left a comment
There was a problem hiding this comment.
Thank you @nikitachapovskii-dev ! The changes seem alright to me.
I have one idea regarding better logging in suspicious cases... but it's not imo strictly necessary ⬇️
| const iframe = await frame.contentFrame(); | ||
|
|
||
| if (iframe) { | ||
| if (iframe && cheerioIframes[index]) { |
Member
Member
There was a problem hiding this comment.
Alternatively, we could just log a warning if the iframe arrays are of different lengths
Contributor
Author
There was a problem hiding this comment.
Thanks for the suggestions!
The second option is probably better as it catches the realistic failure mode (page dynamically adds/removes an iframe) with zero overhead.
The src/srcdoc is more complex and requires an extra getAttribute call per iframe on every crawled page, while the diagnostic would almost never fire 😄
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Pages enforcing a Trusted Types Content Security Policy (e.g. Google Sheets) block any browser-side HTML string assignment — including innerHTML and DOMParser.parseFromString. The iframe expansion in parseWithCheerio used frame.evaluate() to inject iframe content into the browser DOM, which was silently blocked by CSP, causing iframe content to be dropped without any visible error.
The fix moves HTML assembly out of the browser entirely. page.content() is called first, loaded into Cheerio on the Node.js side, and iframe content (fetched via Playwright's Node.js API, which is unaffected by CSP) is substituted directly in the Cheerio tree.
Closes #3588