Phantomjs-onconsolemessage
提供:Dev Guides
PhantomJS-onConsoleMessage()
このコールバックは、Webページでコンソールメッセージが使用されている場合に使用されます。 このコールバックは、次の3つの引数を取ります。
- メッセージ
- 行番号
- ソース識別子
構文
その構文は次のとおりです-
page.onConsoleMessage = function(msg, lineNum, sourceId) {};
例
var wpage = require('webpage').create();
wpage.onConsoleMessage = function(msg) {
console.log('CONSOLE Message: ' + msg );
};
wpage.open('http://localhost/tasks/testl', function(status) {
var script1 = "function(){ console.log('hello world');}";
var value = wpage.evaluate(script1);
phantom.exit();
});
上記のプログラムは、次の output を生成します。
CONSOLE Message: hello world