- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 其他
- 命令行界面
- PhantomJS - 屏幕捕获
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS实用资源
- PhantomJS - 快速指南
- PhantomJS - 实用资源
- PhantomJS - 讨论
PhantomJS - onError()
当出现JavaScript错误时,将调用OnError()方法。onError方法的参数是msg和堆栈跟踪,它是一个数组。
语法
其语法如下−
page.onError = function(msg, trace) {}
示例
以下代码展示了onError()方法的使用方式。
var wpage = require('webpage').create();
wpage.onError = function(msg, trace) {
console.log('CONSOLE Message: ' + msg );
console.log(JSON.stringify(trace));
};
wpage.open('https:///tasks/test.html', function(status) {
phantom.exit();
});
test.html
<html>
<head>
<title>Welcome to phantomjs</title>
</head>
<body>
<script type = "text/javascript">
window.onload = function(){
console.log(page);
}
</script>
<h1>This is a test page</h1>
</body>
</html>
上述程序会生成以下输出。
CONSOLE Message: ReferenceError: Can't find variable: page
[{"file":"https:///tasks/test.html","line":8,"function":"onload"}]
phantomjs_webpage_module_events_callbacks.htm
广告