我在Windows 7上使用PhantomJS 2.0.0并且我不太明白为什么PhantomJS只返回onResourceError回调,而不是onResourceTimeout回调。
var system = require('system');
var page = require('webpage').create();
// Invoked when a web page was unable to load resource.
page.onResourceError = function(resourceError) {
system.stderr.writeLine('onResourceError url: ' + resourceError.url);
phantom.exit();
};
// Invoked when there is a time out when load resource on the web page.
page.onResourceTimeout = function(request) {
system.stderr.writeLine('onResourceTimeout url: ' + request.url);
phantom.exit();
};
// Resource Time out
page.settings.resourceTimeout = 5000; // 5 seconds time out
// Load page with 10 sec. delay
page.open('http://httpbin.org/delay/10');
使用PhantomJS 2.0.0,上面的代码将打印
onResourceTimeout url: http://httpbin.org/delay/10
onResourceError url: http://httpbin.org/delay/10
好像phantom.exit()
上似乎没有{p> page.onResourceTimeout()
使用PhantomJS 1.9.8,上面的代码将打印
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.
编辑:如果我将system.stderr.writeLine
替换为console.log
,使用PantomJS 2.0.0,可以,输出
onResourceTimeout url: http://httpbin.org/delay/10