W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

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

From: Ryosuke Niwa <rniwa@webkit.org>
Date: Fri, 15 Jun 2012 18:23:06 -0700
Message-ID: <CABNRm62FyU+3WQnhzN5-Y5e=RCLm2t3UkkRKC0dRBk=2JD=UtQ@mail.gmail.com>
To: Mihai Parparita <mihaip@chromium.org>
Cc: Adam Klein <adamk@chromium.org>, WebApps WG <public-webapps@w3.org>, Olli@pettay.fi, Rafael Weinstein <rafaelw@chromium.org>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:52 GMT