- 檔案系統模組
- 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
廣告