Cezary Tomczyk wrote:
> There is a website:
https://www.thewhiskyexchange.com/ (I am not
> connected with this site in any way, just testing something) and I
> run from console following method:
>
> document.querySelectorAll('[id]')
>
> The thing is that Google Chrome (OSX El Capitan, Version
> 49.0.2623.87 (64-bit)) and Firefox (OSX El Capitan, , Version 45.0.1)
> returns a list of elements where the first element is an Object.
>
> For document.querySelectorAll('[id]')[0]
>
> I've got:
>
> Object { isProxyNode: true, proxiedNode:
> <script#cfjs_block_e6838f345c>, src: Getter, type: Getter, charset:
> Getter, async: Getter, defer: Getter, crossOrigin: Getter, text:
> Getter, event: Getter, 203 more… }
>
> Is this a bug? Anyone experienced something similar?
This is caused by some Cloudflare sorcery. I'm not sure what exactly is
going on, because those scripts are obfuscated, and reverse-engineering
minfied blobs is not my idea of fun.
All I can tell at the moment is that the first element with an "id"
attribute is a script (added by another script). This injected script is
Cloudflare's Rocket Loader:
http://pastebin.com/raw/bq8y8XHc (pretty-printed)
"Rocket Loader is a general-purpose asynchronous JavaScript loader
coupled with a lightweight virtual browser which can safely run any
JavaScript code after window.onload."
https://support.cloudflare.com/hc/en-us/articles/200168056
Whatever this script does, it's responsible for the "isProxyNode" and
"proxiedNode" properties.
> Because of that I can't use myElement.contains(node). It's throwing
> exception because such object is not a node.
I assume that sites using the Rocket Loader will have to work around
that somehow. This could as simple as excluding scripts from the
selector strings:
querySelectorAll("[id]:not(script)") // instead of "[id]"
If you have to deal with the actual script elements:
myElement.contains(node.proxiedNode || node)
- stefan