Re: Should MutationObservers be able to observe work done by the HTML parser?

On Fri, Jun 15, 2012 at 6:15 PM, Mihai Parparita <mihaip@chromium.org>wrote:

> I used MutationObservers for the first time last night (in Chrome),
> and I was surprised by this behavior. I was working on something that
> transmogrified one node into another, so having observers file during
> parsing would have helpful. Otherwise something like:
>
> <script>var observer = new MutationObserver(/* observer that
> manipulates <foo> tags */);</script>
> <body>
> ....
> <foo></foo>
> <script>
>  /* code that acts on foo tags */
> </script>
>
> If I have to use DOMContentLoaded, then the code in the second
> <script> block would get a chance to operate on <foo> before my
> observer had had a chance to transmogrify it.
>

That is a slightly different issue.

There is no guarantee that your observer is called before the second script
element's script is executed. The only way for that to happen is if the
parser yielded to the event loop immediately after parsing the foo element
but before executing the script element.

- Ryosuke

Received on Saturday, 16 June 2012 01:23:56 UTC