Phantomjs-onerror
提供:Dev Guides
PhantomJS-onError()
OnError()メソッドは、JavaScriptエラーが発生したときに呼び出されます。 onErrorメソッドの引数は msg および stack trace であり、これは配列です。
構文
その構文は次のとおりです-
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('http://localhost/tasks/testl', function(status) {
phantom.exit();
});
testl
<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>
上記のプログラムは、次の output を生成します。
CONSOLE Message: ReferenceError: Can't find variable: page
[{"file":"http://localhost/tasks/testl","line":8,"function":"onload"}]