Phantomjs-onconsolemessage

提供:Dev Guides
2020年6月23日 (火) 08:10時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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