- From: Olli Pettay <Olli.Pettay@helsinki.fi>
- Date: Mon, 21 Jul 2014 16:26:38 +0300
- To: whatwg@whatwg.org
On 07/21/2014 12:21 AM, milakam wrote: > > Hi everyone, > > A BeforeLoad replacement was never discussed as a target use case for > MutationObservers, therefore this message. > > I'm currently creating a JS cross-browser user script and noticed that > only Chromium notifies the MutationObserver for an AddedNode before a > network request is sent (IE and FF don't and won't do anything with the > changes). > > I found the following chromium discussion > https://code.google.com/p/chromium/issues/detail?id=333318 which states > the MO as a replacement for BeforeLoad. MutationObserver shouldn't be used as a replacement for any load related stuff. MutationObserver is about mutations in DOM tree. I think this is great solution > and it would be fantastic if it can be standardized. > No. It would disable several performance optimizations related to page loads. -Olli > My own usecase / testcase I created: > <script type="text/javascript"> > MutationObserver = window.MutationObserver; > var observer = new MutationObserver(function(mutations) { > mutations.forEach(function(mutation) { > var addedNodes = mutation.addedNodes; > for (var i = 0; i < addedNodes.length; i++) { > if (addedNodes[i].nodeName == 'SCRIPT') { > addedNodes[i].src = 'good.js'; > } > } > > }); > }); > observer.observe(document, {childList: true, subtree: true}); > </script> > <script type="text/javascript" src="evil.js"></script> > > In chrome this works out of the box and "good.js" is called directly > (without sending any network requests beforehand, if it would be stored > externally). In FF only "evil.js" is called. The source is updated > within DOM afterwards, but there's no network request or parsing of the > updated script (apart from the DOM change it has no effect). > In FF it's currently only possible with an internal extension like (e.g. > usecase > http://stackoverflow.com/questions/5330048/event-before-load-event-for-firefox-extension): > Components.classes["@mozilla.org/observer-service;1"] > .getService(Components.interfaces.nsIObserverService) > .addObserver({ > observe: function(aSubject, aTopic, aData) { > if ("http-on-modify-request" == aTopic) { > var url = aSubject > .QueryInterface(Components.interfaces.nsIHttpChannel) > .originalURI.spec; > if (url && url.match('facebook')) { > aSubject.cancel(Components.results.NS_BINDING_SUCCEEDED); > } > } > } > }, "http-on-modify-request", false); > > I didn't test it in in Konqueror. > > Greetz > MM > >
Received on Monday, 21 July 2014 13:27:09 UTC