Your Browser Will Block XSS for You Now. Almost Nobody Has Turned It On.
Trusted Types hit Baseline in February 2026 and blocks DOM XSS at the API level. Adoption is under 3%. Here is the rollout that works.
Kemal Esensoy·Modified on October 31, 2026
On February 24, 2026, Firefox 148 shipped support for the Trusted Types API. That was the last browser engine holding out, and with it the feature crossed into Baseline Newly Available. I checked this on api.webstatus.dev rather than trusting a blog post, because Baseline claims get repeated wrong all the time. The data is unambiguous: Chrome 83 in May 2020, Safari 26 in September 2025, Firefox 148 in February 2026, Baseline low date 2026-02-24.
So every major browser now ships a mechanism that structurally blocks DOM-based XSS. Not filters it. Blocks it at the API level.
Now the depressing part. The 2025 Web Almanac found require-trusted-types-for on 2.67% of desktop pages that send a Content Security Policy at all, and only 21.9% of pages send a CSP in the first place. The mobile number looks better at 12.10%, but that is an artifact: the third most common CSP header value in the entire crawl is require-trusted-types-for 'script';report-uri /checkin/_/AndroidCheckinHttp/cspreport, which is Google's own Android infrastructure reporting to Google's own endpoint. Strip that out and adoption is a rounding error.
A browser feature that eliminates an entire vulnerability class has been available in Chrome for six years and almost nobody has turned it on.
Why DOM XSS Survived Every Other Mitigation
Cross-site scripting has three flavours, and people conflate them constantly. Reflected and stored XSS happen on the server: your backend takes attacker input and prints it into the HTML response. Template auto-escaping and output encoding largely solved those. Modern frameworks escape by default and you have to work to break it.
DOM-based XSS never touches your server. Attacker-controlled data goes into a client-side "sink" and the browser executes it. The sink list is short and boring: innerHTML, outerHTML, insertAdjacentHTML, document.write, iframe.srcdoc, DOMParser.parseFromString, <script src> and script text, <embed src>, <object data>, plus the runtime compilers eval, new Function, and the string forms of setTimeout and setInterval.
Content Security Policy handles a lot of this. A strict script-src with nonces kills most injected <script> tags. But CSP works on where scripts come from, not on what your own trusted script does with a string. If your own bundle, running under your own nonce, reads a value out of location.hash and assigns it to element.innerHTML, CSP sees an approved script doing an approved thing. The injection sails straight through the filter you installed.
That is the exact gap Trusted Types closes, and it is the reason the feature exists as a separate thing rather than another script-src keyword.
Worth being precise here, because this gets oversold: Trusted Types does nothing for reflected or stored XSS in server-rendered output. It guards DOM sinks. That is a big class, it is the class that survived everything else, but it is one class.
It Is a Type Check, Not a Sanitizer
Here is the mental model that made it click for me. Trusted Types does not clean your strings. It refuses to accept strings at all.
Once the policy is enforced, element.innerHTML = someString throws a TypeError. Full stop. The only thing the browser will accept at that sink is a TrustedHTML object, and the only way to get one is to run your string through a policy you registered by name. The value carries proof that it passed through your code. It cannot be forged, and it cannot be produced accidentally.
You turn it on with two CSP directives:
Content-Security-Policy: require-trusted-types-for 'script'; trusted-types my-sanitizer;
require-trusted-types-for 'script' is what actually locks the sinks. trusted-types is the allowlist of policy names anyone on the page may create. Names accept alphanumerics plus -#=_/@.%. You can write * to allow any name, 'none' to allow none, and 'allow-duplicates' if some library insists on registering the same policy name twice. If you skip the trusted-types directive entirely, no policy can be created, which is a very effective way to break your own site.
The policy itself is small:
if (window.trustedTypes && trustedTypes.createPolicy) {
const policy = trustedTypes.createPolicy('my-sanitizer', {
createHTML: (input) => DOMPurify.sanitize(input, { RETURN_TRUSTED_TYPE: true }),
});
el.innerHTML = policy.createHTML(userInput); // fine
el.innerHTML = userInput; // TypeError
}
Three callbacks exist: createHTML, createScript, and createScriptURL. Only define the ones you need. A policy that only implements createHTML will throw if someone tries to route a script URL through it, which is exactly what you want.
The feature-detection guard matters more than it looks. trustedTypes is undefined in older browsers, and unguarded calls to trustedTypes.createPolicy are a reliable way to white-screen a site for anyone on a stale browser. Baseline Newly Available means current versions of everything, not everyone's actual browser.
The Default Policy Is Where People Cheat
There is one escape hatch, and it is the reason some deployments provide zero security while showing a green checkmark.
If you register a policy literally named default, the browser calls it automatically whenever a bare string hits a guarded sink, instead of throwing. It looks like a migration shortcut. Legacy code keeps working, no errors, ship it.
Then somebody writes this:
trustedTypes.createPolicy('default', {
createHTML: (s) => s, // this does nothing
});
That satisfies the type system and sanitizes nothing. You have added a header, passed a scanner, and kept every DOM XSS bug you had, now with documentation claiming you fixed it. If you use a default policy, it has to actually sanitize, ideally with DOMPurify, and you should treat it as a temporary bridge with a deadline rather than the finished state. Named policies at each call site are the real target, because they let you audit which code is allowed to produce HTML.
Google's own numbers are the argument for doing this properly. Their case study on adopting the API across production frameworks reports deployment across more than 130 services with zero incidence of DOM XSS in those applications, and analysis of their Vulnerability Reward Program submissions found it would have prevented at least 61% of the DOM XSS bugs their static analysis pipeline missed. The Angular integration took four security engineers and one intern about six weeks. That is a real cost, and it is also proof this is finite work rather than an endless program.
Report-Only First, or You Will Break Production
Do not enforce on day one. The rollout that works has four steps, and the first one is free.
Start by shipping the report-only header alongside your existing CSP:
Content-Security-Policy-Report-Only: require-trusted-types-for 'script'; report-uri /csp-report
Nothing breaks. The browser sends you a violation report every time code touches a guarded sink. You can also watch them live in the console while you develop:
document.addEventListener('securitypolicyviolation', console.error.bind(console));
Then you read the reports, and this is the part that takes the time. Each violation names a file and a line. Some of them are yours and get fixed by routing through a policy or, better, by replacing innerHTML with textContent where you were never producing HTML in the first place. A surprising number of sinks in a typical codebase are just setting text.
Third, you add trusted-types with your policy names while still in report-only, so you catch anything trying to create a policy you did not expect.
Only then do you flip the header to enforcing. Keep report-uri after you enforce. Reports do not stop being useful the day you turn the switch.
Budget real calendar time for step two. This is not a header you add on a Friday afternoon, unlike most of the security hardening work that actually is that quick.
What Actually Breaks
The reason adoption is near zero is not that the API is hard. It is that your page is not only your code.
Tag managers are the worst offender. Google Tag Manager injects and evaluates arbitrary marketing snippets by design, which is the precise behaviour the feature forbids. Ad tags, chat widgets, session recorders, A/B testing scripts and heatmap tools all write HTML into your page from strings. Every one of those becomes a violation, and you do not control their source.
Older jQuery is a classic hit. $(html), .html(), and .append() with a markup string all end up at innerHTML. Any plugin from the 2015 era does this constantly.
Your own build tooling may surprise you too. Inlined SVG, template compilers, and anything that hydrates markup from a string can generate innerHTML assignments you never wrote.
The honest answer for third parties is that you have three options: get the vendor to ship a Trusted Types compatible build, allowlist their policy name if they register one properly, or drop the script. Microsoft's Clarity added custom policy support, which shows vendors will move when asked, but most have not. This is the same dependency problem I wrote about in the npm supply chain post: your security posture is capped by the least careful script on your page.
Where the Frameworks Stand
Angular is the best supported by a distance, because Google built the integration as part of the case study above. It works, and it deliberately refuses bypassSecurityTrustHtml, which is the correct behaviour and will annoy you.
React supports Trusted Types values in dangerouslySetInnerHTML and for attribute interpolation, but the full integration has sat behind an internal enableTrustedTypesIntegration flag rather than being on by default. In practice React apps that avoid dangerouslySetInnerHTML mostly work, and the ones that use it need a policy at each call site.
Vue integrated reasonably early and the surface area that breaks is small, since the compiler avoids string HTML in most render paths. The runtime compiler and v-html are your problem spots.
Svelte is the awkward one. The compiler emits innerHTML assignments for static markup and inline SVG, which trips enforcement even though the strings are compile-time constants with no user data anywhere near them. There are open issues on both Svelte and SvelteKit about this. Check your compiled output before you promise anyone a date.
The general rule: if your framework generates HTML from strings at runtime, expect a shim. If it builds DOM nodes directly, you are mostly fine.
Who Should Actually Bother
I am not going to tell you every site needs this.
A five-page brochure site with a contact form, no user accounts, no user-generated content and no dynamic DOM writing gets close to nothing from Trusted Types. There is no DOM XSS surface to protect. Spend that time on things that matter more at that size, like deleting the scripts you are not using or keeping your framework patched, which is what actually bit people during the Next.js CVEs in August.
It earns its keep when you have any of these: user-generated content rendered into the page, a logged-in dashboard, a CMS admin where editors paste HTML, a rich text editor, anything that renders Markdown client-side, or an app where a URL parameter influences what gets drawn. Those are the shapes where DOM XSS lives, and where a single missed sink is an account takeover.
There is a second reason to care that has nothing to do with your own code. If you are shipping applications assembled fast with AI assistance, innerHTML shows up in generated code constantly, because the training data is full of it. I wrote about that habit in the vibe coding security post. A build-time lint rule catches some of it. A browser that refuses the assignment catches all of it, including the code you never reviewed.
What I Actually Think
This is a good feature with a bad adoption story, and the adoption story is not the browsers' fault. The work is not writing the policy, which takes twenty minutes. The work is auditing every sink in a codebase you inherited and negotiating with vendors who have no reason to care. That is unglamorous, it does not demo well, and nobody approves a sprint for it.
What changed in February 2026 is that the excuse is gone. "Chrome only" was a legitimate reason to skip this for six years. It is not one now.
If I were prioritising, I would put the report-only header on any application with a login screen this quarter, purely to find out how bad it is. The report costs you one header and tells you something real about your codebase. Whether you enforce afterwards is a decision you can make with actual data instead of a guess.
If you want a second pair of eyes on your CSP, your sinks, or the general question of what is worth hardening on your site and what is theatre, that is a decent chunk of what I do at Wunderlandmedia.
Find these posts useful? Mark Wunderlandmedia as a preferred source on Google — my articles will then show up more often in your Search results, AI Overviews and AI Mode.
Set as preferred sourceAbout the Author
Kemal Esensoy
Kemal Esensoy, founder of Wunderlandmedia, started his journey as a freelance web developer and designer. He conducted web design courses with over 3,000 students. Today, he leads an award-winning full-stack agency specializing in web development, SEO, and digital marketing.