LibWeb/HTML: Do not run script on child removal

Matching the behaviour of the other big three browser engines,
also tested by WPT, but does not appear to be explicitly specified.

I also noticed when investigating that browser engines disagree
about whether a child mutation should trigger script execution.
For this, I've just gone with the behaviour of Webkit/Chromium of
not running script.
This commit is contained in:
Shannon Booth 2026-03-18 13:45:07 +01:00 committed by Jelle Raaijmakers
parent cc6536b527
commit 27436c3971
Notes: github-actions[bot] 2026-03-19 08:47:52 +00:00
4 changed files with 53 additions and 0 deletions

View file

@ -652,6 +652,12 @@ void HTMLScriptElement::children_changed(ChildrenChangedMetadata const& metadata
{
Base::children_changed(metadata);
// AD-HOC: Avoid running script on child removal, matching the behaviour of other browsers.
// We also do not run script on child mutation, matching the behaviour of chromium and webkit.
// See: https://github.com/whatwg/html/issues/12279
if (metadata.type != ChildrenChangedMetadata::Type::Inserted)
return;
// 1. If the script element is not connected, then return.
if (!is_connected())
return;