Closed Bug 1784187 Opened 2 years ago Closed 1 year ago

Empty scripts should be executed too


(Core :: DOM: Core & HTML, defect)

Firefox 105



107 Branch
Tracking Status
firefox107 --- fixed


(Reporter: tristan.fraipont, Assigned: avandolder)



(2 files)

Attached file test-case.html

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0

Steps to reproduce:


Register a MutationObserver on the body looking for added nodes in the body's subtree, which will log the innerHTML of an element with id "parent".
Below in the markup, set this one:

<div id="parent">
  <!--Further content-->

Actual results:

When the MutationObserver fires the whole "parent" element has been completely parsed and the innerHTML includes the comment "<!--Further content-->".

Expected results:

Basically, the innerHTML should have contained only "<script></script>".

Reasoning: the empty <script></script> should have triggered the "run a classic script" algorithm, which itself should have called the cleanup after running a script steps, which should have triggered a microtask-checkpoint, ultimately forcing the MutationObserver's pending records to be signaled and handled, with what the parser had until the end tag </script>.
If you want to go the full route, when the end tag </script> is met, we're in From there in "prepare the script element" source text is set to the empty string, and further down no special handling of the empty string is ever mentioned, so it should get executed normally, just like it happens when we had just a single white space character between the script's tags.

Ps: this is not a regression, I went back to M61 where it also did reproduce.

This seems to be a Gecko bug for MutationObserver.

Olli, are we still actively working on MutationObserver? Is this something that we should fix?

Severity: -- → S2
Flags: needinfo?(smaug)

Doesn't look like a MutationObserver issue, but rather an issue with script handling. We're returning early somewhere because of empty content.
I think,96
which calls,245

Flags: needinfo?(smaug)

Adam, do you want to give it a try? :)

Flags: needinfo?(avandolder)

I will give it a shot!

Assignee: nobody → avandolder
Ever confirmed: true
Flags: needinfo?(avandolder)
Pushed by
Process scripts even if they contain no text content. r=smaug
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 107 Branch
Regressions: 1827512
No longer regressions: 1827512
You need to log in before you can comment on or make changes to this bug.