- From: Rafael Weinstein <rafaelw@google.com>
- Date: Sat, 16 Jun 2012 08:04:10 +0300
- To: Ryosuke Niwa <rniwa@webkit.org>
- Cc: Mihai Parparita <mihaip@chromium.org>, Adam Klein <adamk@chromium.org>, WebApps WG <public-webapps@w3.org>, Olli@pettay.fi
I too thought we had intentionally spec'd them to not fire during load. The HTML spec is clear about this WRT Mutation Events: http://www.whatwg.org/specs/web-apps/current-work/#tree-construction: "DOM mutation events must not fire for changes caused by the UA parsing the document. (Conceptually, the parser is not mutating the DOM, it is constructing it.) This includes the parsing of any content inserted using document.write() and document.writeln() calls." It seems like this should also apply to Mutation Observers, unless we have compelling reasons to do otherwise. On Sat, Jun 16, 2012 at 4:23 AM, Ryosuke Niwa <rniwa@webkit.org> wrote: > 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 05:04:39 UTC