Javascript 幻影不';在onResourceTimeout回调上无法退出
我在Windows7上使用PhantomJS2.0.0,我不太明白为什么PhantomJS只返回onResourceError回调,而不返回onResourceTimeout回调Javascript 幻影不';在onResourceTimeout回调上无法退出,javascript,windows,phantomjs,Javascript,Windows,Phantomjs,我在Windows7上使用PhantomJS2.0.0,我不太明白为什么PhantomJS只返回onResourceError回调,而不返回onResourceTimeout回调 var-system=require('system'); var page=require('webpage')。create(); //当网页无法加载资源时调用。 page.onResourceError=函数(resourceError){ system.stderr.writeLine('onResourceE
var-system=require('system');
var page=require('webpage')。create();
//当网页无法加载资源时调用。
page.onResourceError=函数(resourceError){
system.stderr.writeLine('onResourceErrorURL:'+resourceError.url);
phantom.exit();
};
//在网页上加载资源时出现超时时调用。
page.onResourceTimeout=函数(请求){
system.stderr.writeLine('onResourceTimeout url:'+request.url);
phantom.exit();
};
//资源超时
page.settings.resourceTimeout=5000;//5秒超时
//用10秒加载页面。延迟
第页打开('http://httpbin.org/delay/10');
使用PhantomJS 2.0.0,将打印上述代码
onResourceTimeout url: http://httpbin.org/delay/10
onResourceError url: http://httpbin.org/delay/10
onResourceTimeout url: http://httpbin.org/delay/10
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file://OnRessourceTimeOut.js. Domains, protocols and ports must match.
phantom.exit()
似乎没有在page.onResourceTimeout()上调用
使用PhantomJS 1.9.8,上述代码将打印出来
onResourceTimeout url: http://httpbin.org/delay/10
onResourceError url: http://httpbin.org/delay/10
onResourceTimeout url: http://httpbin.org/delay/10
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file://OnRessourceTimeOut.js. Domains, protocols and ports must match.
编辑:如果我用console.log
替换system.stderr.writeLine
,使用PantomJS 2.0.0,就可以了,输出是
onResourceTimeout url: http://httpbin.org/delay/10
PhantomJS 1.9.x是否具有相同的行为?两张照片的时差是多少?退出需要一点时间,所以可以打印第二行。两次打印之间没有ime差异。我用PhantomJS 1.9.8测试更新了我的帖子。所以,这里并没有什么问题。我的猜测是,退出是异步进行的,以便可以执行其他代码,但速度足够快,不会执行太多代码。这也可能与1.9.8中引入的一个bug的解决方案有关,您在这里将其视为“不安全的JavaScript…”。我使用replacesystem.stderr.writeLinebyconsole.log
编辑我的文章。1.9.8问题:不安全的JavaScript试图访问1.9.8#12697()中的帧