Envision the following script:
const scoped_registry = new CustomElementRegistry();
scoped_registry.define("forbidden-element", class ForbiddenElement : HTMLElement {
constructor() {
super();
console.log("This should not be called");
}
});
const container = document.createElement("div", {customElementRegistry: scoped_registry });
container.setHTMLUnsafe(
"<forbidden-element></forbidden-element>", {
sanitizer: {removeElements: ["forbidden-element"]}
});
According to the current spec, the console would log "This should not be called".
That is because:
- the sanitizer API calls the fragment parser
- In turn, the fragment parser uses the custom element registry of the context element
- Parsing happens before sanitization
- Custom element constructors happen straight away when an element is created.