jsdom not loading or not running external scripts in page

无人久伴 提交于 2019-12-14 03:50:53

问题


Cross-posted from https://github.com/tmpvar/jsdom/issues#issue/127

I will post a minimal test case in the next day or so - but I wanted to see if anyone else had the same problem - or if (more likely) if I am doing something stupid.

I'm using NodeJS v2.6 on Ubuntu 10.04 AMD64 and jsdom@0.1.23.

var file = readFileSync("./www/index.html", "utf8"); var window = jsdom.jsdom(file).createWindow();

All inline scripts run, but complain about missing variables which should be supplied by the external scripts.

I have tried setting a url in the options and I have tried using full (http://...) urls in the src attributes,

I have tried jQuerify (using default jQuery path) and that works fine, though it only brings in jQuery and I'm still missing all of the other scripts.

Any pointers before I post failing code/urls?

Thanks,

Chris.


回答1:


As of jsdom 0.2.0 this has become much easier. Please see the "Easy mode" section in the readme. jsdom.env() will not execute scripts found in the page by default making what you are trying to do, much easier.




回答2:


I removed all in-line Javascript from the page - luckily the page is under my control.



来源:https://stackoverflow.com/questions/4711655/jsdom-not-loading-or-not-running-external-scripts-in-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!