3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phantomjsで出るエラーだけ追うスクリプト

Posted at

phantomjsで某ページのスクリーンショット撮る、ってのがしたかったんですが、
どうも他のブラウザでは出てないけど、phantomでだけエラーが出てる! ということが分かり、
それだけ見つけるためのスクリプト書いてみました。

(書いたというか、examplesつなぎあわせ)

errortracker.js
var system = require('system');
var url = system.args[1];

if (!/^https?:\/\//.test(url)) {
    console.error('Pass a url!');
    phantom.exit();
}

phantom.onError = function(msg, trace) {
    var msgStack = ['PHANTOM ERROR: ' + msg];
    if (trace && trace.length) {
        msgStack.push('TRACE:');
        trace.forEach(function(t) {
            msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function + ')' : ''));
        });
    }
    console.error(msgStack.join('\n'));
    phantom.exit(1);
};

var page = require('webpage').create();
// page.viewportSize = { width: 320, height: 480 };
page.open(url, function (status) {
    if (status !== 'success') {
        console.error('Unable to access the network!');
        phantom.exit(1);
    }
    // phantom.exit();
});

こんなかんじで使う。

phantomjs errortracker.js http://fnobi.com/

まぁ、phantomjsあんまり使い慣れてなかったので、
ちょうどよい慣らしということで。

参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?