Power wrote:But have you any idea why script surrogates affected page styles?
Starting with Gecko 1.9.0, javascript: URIs are loaded asynchronously.
Therefore using the old
location.href="javascript:x()" to inject content Javascript safely in a web page doesn't serve the purpose anymore for page-level surrogates, which need to run
synchronously before the page content starts to be parsed.
Using Components.utils.Sandbox doesn't work either, because it wraps the DOM, thus preventing tricks like method or getter substitution which are used routinely by most surrogates.
So I had to find an alternate injection method, and came up with insertion and automatic deletion of <script> DOM nodes.
But as soon as I reference
document.documentElement (needed as an anchor node), Gecko creates a temporary minimal DOM: in Gecko < 1.9.1, this sets the "quirks mode" flag (because there's no DOCTYPE at that time), and it's never reset when a DOCTYPE is actually found, later. In Gecko 1.9.1 and above the DOCTYPE gets honored as soon as it's found, no matter what had happened earlier.
Now, working around on Gecko 1.8.x was relatively simple: I just reverted to the old
location.href method.
Gecko 1.9.0 was a tougher beast, since as I said this method won't work for page surrogates and I need to stick with DOM insertion.
However your suggestion about Stylish provided with a hackish but effective work-around: just after page surrogates have run, I add and remove an empty AGENT stylesheet, which causes the layout flags to be reset.
Of course, these tricks are unneeded on Gecko 1.9.1 and above, therefore now we've got three code paths for page-level surrogates. Ouch.
[quote="Power"]But have you any idea why script surrogates affected page styles?[/quote]
Starting with Gecko 1.9.0, javascript: URIs are loaded asynchronously.
Therefore using the old [i]location.href="javascript:x()"[/i] to inject content Javascript safely in a web page doesn't serve the purpose anymore for page-level surrogates, which need to run [i]synchronously[/i] before the page content starts to be parsed.
Using Components.utils.Sandbox doesn't work either, because it wraps the DOM, thus preventing tricks like method or getter substitution which are used routinely by most surrogates.
So I had to find an alternate injection method, and came up with insertion and automatic deletion of <script> DOM nodes.
But as soon as I reference [i]document.documentElement[/i] (needed as an anchor node), Gecko creates a temporary minimal DOM: in Gecko < 1.9.1, this sets the "quirks mode" flag (because there's no DOCTYPE at that time), and it's never reset when a DOCTYPE is actually found, later. In Gecko 1.9.1 and above the DOCTYPE gets honored as soon as it's found, no matter what had happened earlier.
Now, working around on Gecko 1.8.x was relatively simple: I just reverted to the old [i]location.href[/i] method.
Gecko 1.9.0 was a tougher beast, since as I said this method won't work for page surrogates and I need to stick with DOM insertion.
However your suggestion about Stylish provided with a hackish but effective work-around: just after page surrogates have run, I add and remove an empty AGENT stylesheet, which causes the layout flags to be reset.
Of course, these tricks are unneeded on Gecko 1.9.1 and above, therefore now we've got three code paths for page-level surrogates. Ouch.