gpt4 book ai didi

javascript - 为什么我的 casperjs 没有显示任何错误?

转载 作者:行者123 更新时间:2023-11-28 18:30:27 24 4
gpt4 key购买 nike

var casper = require('casper').create({
logLevel:'deubg',
verbose:true,
});

casper.start(someurl,function(){
not_existing_function();
})

当执行上面的代码时,我在屏幕上看到的只是调试信息,这对我来说意义不大。我希望看到一些错误,指出被调用的函数不存在,但实际上并不存在。

我以为这只是行为,直到我看到this .

这个问题清楚地表明他收到了一些错误消息:

ReferenceError: Can't find variable: $

为什么我在屏幕上看不到类似的内容?

最佳答案

您可能正在使用 PhantomJS 2.x。它有一个 known bug其中一些错误没有报告。这包括您所描述的错误类别。

此外,注册 CasperJS/PhantomJS 的各种错误事件在这种情况下并没有帮助,但这里只是以防万一:

// http://phantomjs.org/api/phantom/handler/on-error.html
phantom.onError = function(msg, trace) {
var msgStack = ['PHANTOM ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
});
}
console.error(msgStack.join('\n'));
phantom.exit(1);
};

// http://docs.casperjs.org/en/latest/events-filters.html#remote-message
casper.on("remote.message", function(msg) {
this.echo("Console: " + msg);
});

// http://docs.casperjs.org/en/latest/events-filters.html#page-error
casper.on("page.error", function(msg, trace) {
this.echo("Error: " + msg);
// maybe make it a little fancier with the code from the PhantomJS equivalent
});

// http://docs.casperjs.org/en/latest/events-filters.html#resource-error
casper.on("resource.error", function(resourceError) {
this.echo("ResourceError: " + JSON.stringify(resourceError, undefined, 4));
});

// http://docs.casperjs.org/en/latest/events-filters.html#page-initialized
casper.on("page.initialized", function(page) {
// CasperJS doesn't provide `onResourceTimeout`, so it must be set through
// the PhantomJS means. This is only possible when the page is initialized
page.onResourceTimeout = function(request) {
console.log('Response Timeout (#' + request.id + '): ' + JSON.stringify(request));
};
});

您可以在脚本上运行 eslint 或 jshint 之类的东西来捕获语法错误,并且您可以在 PhantomJS 1.9.8/1.9.7 中运行脚本来捕获此类错误。

关于javascript - 为什么我的 casperjs 没有显示任何错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38110796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com