[whatwg/dom] Request for mechanism to determine if children changed steps are called as a result of script or parser (Issue #1288)

### What problem are you trying to solve?

In [TrustedTypes](https://w3c.github.io/trusted-types/dist/spec) we have a need to distinguish between a script's children being changed by an API (e.g. script.appendChild) or changed by the parser.

This is specifically needed as we treat all parsed scripts as trusted by default. However, it's possible for a script to be manipulated before it's finished parsing, and in those cases it shouldn't be trusted.

### What solutions exist today?

Both Chromium and WebKit implement a childrenChanged function on their ContainerNode type which I believe translates to the [children changed steps](https://dom.spec.whatwg.org/#concept-node-children-changed-ext) concept defined in the DOM algorithm. However, unlike the spec Chromium and WebKit both provide an argument to the function with details, such as the type (what changed and how it changed), and importantly the source of the change (parser vs API).

We can (and do) use this to invalidate scripts in the above described situation.

### How would you solve it?

It would be good if the DOM spec matched the reality of at least 2 implementations (unsure about Gecko), and provided details about the change, at the very least for this use case the source of the change.

### Anything else?

See https://github.com/w3c/trusted-types/pull/499#discussion_r1552467536 for a long discussion that lead to this issue being raised.

I'm open to any alternative spec mechanisms we can use to spec this behaviour, so if there's a way today or a simpler change we can use let me know.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1288
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1288@github.com>

Received on Thursday, 16 May 2024 12:56:08 UTC