-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSDOM does not load <script> javascript code recursively #640
Comments
Can you should that this behavior is different in a browser? I am pretty sure asynchronously-inserted script tags, e.g. ones inserted from inside another script tag, do not delay the window's |
Sounds to be a reasonable explanation to me ; but then which event should be used/how to get the full populated DOM? |
I'm not sure; what event would you normally use in a browser? To be clear, jsdom is happy to take bugs where its behavior demonstrably differs from that of a browser. So if you can create a test case to that effect, please let us know! But if there's no difference, it's not really our job to give you tech support on how the web platform works... StackOverflow might be a better place for that. |
I'm also not sure if this is an issue with jsdom, an incompetence on my side (don't know the event name) or simply a use case jsdom can't satisfy. I just know that at http://en.wikipedia.org, we have 23 scripts nodes, most of them created dynamically. If you save the page statically with your browser, you can see them. Using jsdom "load" event, only 11 of them are created, and it seems to me no event are sent after all javascripts are executed or similar, so I have no way to retrieve a dom with this 23 nodes. |
Seems to me, this could be related to #380 because at http://en.wikipedia.org, javascript code is partly loaded dynamically using "ajax" type requests. So, if xmlhttprequest is "not working" in jsdom, then this is pretty clear why all scripts are loaded... |
It is true, dynamically inserted scripts load asynchronously. When the document fires the There is no event defined to tell the browser when all dynamically generated script tags have loaded because there is no possible way for the browser to know how many script tags will be generated in the future. Imagine it, you run a The solution is either in the documentation of your module loader or, you will have to create your own signal letting you know that all the dynamic scripts have been loaded. Then, you'll wait for this signal before asking jsdom to do whatever it is that you want it to do after all dynamically injected scripts have been executed. The equivalent user action is navigating to a page, waiting for it to load completely, and then viewing the "live" source of the page with @domenic Maybe a wiki article about this would help? I understand not wanting to reiterate every tip and trick about dealing with the live dom and http protocols but this is something pretty basic that is often a cause of confusion for people first using a headless browser. http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/ |
Hmm, I think that really nice treatise you just wrote, @matthewkastor, should be pretty helpful :). Yeah, maybe I'll close this, since it does seem nobody can demonstrate something different from a browser, and then open a new one to add a quick pointer in the readme of some sort. Thanks. |
Closed in favor of #675. |
If you have a script1 which create a script2 tag which itself create a script3 tag, then only script1 and script2 are listed in the DOM using the following code:
It looks like jsdom does not evaluate the code of script2, so jsdom does not seem to work recursively. This is a problem in my case. How to fix that?
The text was updated successfully, but these errors were encountered: