Skip to content

fix: use DOMParser instead of innerHTML in process_iframes#1796

Open
Br1an67 wants to merge 1 commit intounclecode:mainfrom
Br1an67:fix/issue-1582-trusted-html
Open

fix: use DOMParser instead of innerHTML in process_iframes#1796
Br1an67 wants to merge 1 commit intounclecode:mainfrom
Br1an67:fix/issue-1582-trusted-html

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

Fixes #1582

Sites with Trusted Types Content Security Policy (like Google properties) block direct innerHTML assignment, causing TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML'.

Replaced div.innerHTML = ... with DOMParser.parseFromString() which parses the HTML safely and moves child nodes into the replacement div without triggering the Trusted Types policy.

List of files changed and why

crawl4ai/async_crawler_strategy.py — In process_iframes(), replaced innerHTML assignment with DOMParser + DOM node transfer approach.

How Has This Been Tested?

Verified the DOMParser approach produces equivalent DOM output to innerHTML while being Trusted Types-safe. DOMParser is supported in all modern browsers.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Sites with Trusted Types CSP block direct innerHTML assignment. Replace
with DOMParser.parseFromString() which is Trusted Types-safe and moves
parsed child nodes into the replacement div.

Closes unclecode#1582
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.

[Bug]: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML'

1 participant