Sanitizer API: A javascriptURLs Switch in Chrome 159
Chrome 159 reached the beta channel on November 12, 2026, with stable scheduled for December 8, 2026. It brings a small option with a wide blast radius to the Sanitizer API: javascriptURLs, added to SanitizerConfig and to the Sanitizer object itself. What matters more than the Chrome milestone is where it landed first — the WHATWG HTML specification. Stripping javascript: URLs stops being a side effect of which method was called and becomes a declared line in the configuration.
The problem: "clean" is not "safe"
Writing user-supplied HTML straight into innerHTML is the shortest path to XSS. That is the gap the Sanitizer API closes: setHTML() parses, sanitizes, and inserts in one step, dropping script elements, on* event handlers, and anything outside its built-in allowlist.
But the API exposes two doors. setHTML() and parseHTML() can only be made stricter, never more permissive. setHTMLUnsafe() and parseHTMLUnsafe() accept a looser configuration. The trouble was that javascript: URL removal rode along on the method being "safe" — whether <a href="javascript:..."> survived depended on the function name typed at the call site rather than on anything declared in the configuration. A team that needed one extra element through the gate silently gave up a protection unrelated to that element.
What changed
Per the specification change, javascriptURLs follows the same logic as the existing comments and dataAttributes members: a boolean in the configuration instead of implicit behavior. It also applies in the removeUnsafe() path, so tightening a permissive configuration back down becomes one explicit operation rather than a switch of entry point.
Default behavior is unchanged. Code that passes no option gets exactly what it got before. The value here is disclosure: the configuration now reads as a written security policy, reviewable in a pull request like any other line.
A practical example
// Default path: setHTML() drops script, event handlers, and javascript: URLs
comment.setHTML(untrustedHTML);
// A wider configuration — with javascript: URLs declared out of bounds
const sanitizer = new Sanitizer({
elements: ["p", "a", "b", "em", "code"],
attributes: ["href", "class"],
comments: false,
dataAttributes: false,
javascriptURLs: false, // new in Chrome 159
});
comment.setHTMLUnsafe(untrustedHTML, { sanitizer });Feature detection is still mandatory:
if ("setHTML" in Element.prototype) {
target.setHTML(untrustedHTML);
} else {
// fallback until the other engines catch up
}Worth knowing: new Sanitizer() rejects contradictory configurations with a TypeError. elements and removeElements cannot both be defined, nor attributes and removeAttributes at the global level, and an element listed in replaceWithChildrenElements cannot also appear in elements. The error surfaces when the object is constructed, not on the first hostile payload — which is the right time for it.
Real-world caveats
- Availability is limited. MDN marks the Sanitizer API as not Baseline: it does not work in some of the most widely used browsers. Gecko and WebKit have open reports for this specific option, but shipping is not complete. A DOMPurify fallback stays necessary in production.
- Defaults did not move. The option grants no extra permissiveness to
setHTML(); that method remains non-extensible by design. - Client-side sanitization is not the only layer. Chrome's own guidance is explicit: sanitize on the server too, and keep both rule sets consistent.
- Trusted Types remains complementary.
setHTML()needs no Trusted Types policy, but a fallback that writes toinnerHTMLwill need one underrequire-trusted-types-for 'script'. - Older engines ignore it quietly. An unknown configuration member is dropped without complaint, so its presence in source is not evidence that it is being enforced.
Takeaway
The value of this change is not a new line of code. It is the move of a security decision from convention into written configuration. A policy that can be read is a policy that gets reviewed, and a reviewed policy is the one still standing a year and a team rotation later. The practical step today: find every setHTMLUnsafe() call site in the codebase and ask what each one actually needed the permissive door for. The answer usually reveals a configuration that can now be narrowed out loud.
Primary sources: the Chrome 159 release notes and the WHATWG HTML specification change, plus the Sanitizing Untrusted HTML guide inside Modern Web Guidance.