Last active
March 15, 2016 04:01
-
-
Save carlesso/0eae30df36558139f926 to your computer and use it in GitHub Desktop.
Phantom Tumblr https error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = require('webpage').create(); | |
var system = require('system'); | |
page.onResourceRequested = function (request) { | |
system.stderr.writeLine('= onResourceRequested()'); | |
system.stderr.writeLine(' request: ' + JSON.stringify(request, undefined, 4)); | |
}; | |
page.onResourceReceived = function(response) { | |
system.stderr.writeLine('= onResourceReceived()' ); | |
system.stderr.writeLine(' id: ' + response.id + ', stage: "' + response.stage + '", response: ' + JSON.stringify(response)); | |
}; | |
page.onLoadStarted = function() { | |
system.stderr.writeLine('= onLoadStarted()'); | |
var currentUrl = page.evaluate(function() { | |
return window.location.href; | |
}); | |
system.stderr.writeLine(' leaving url: ' + currentUrl); | |
}; | |
page.onLoadFinished = function(status) { | |
system.stderr.writeLine('= onLoadFinished()'); | |
system.stderr.writeLine(' status: ' + status); | |
}; | |
page.onNavigationRequested = function(url, type, willNavigate, main) { | |
system.stderr.writeLine('= onNavigationRequested'); | |
system.stderr.writeLine(' destination_url: ' + url); | |
system.stderr.writeLine(' type (cause): ' + type); | |
system.stderr.writeLine(' will navigate: ' + willNavigate); | |
system.stderr.writeLine(' from page\'s main frame: ' + main); | |
}; | |
page.onResourceError = function(resourceError) { | |
system.stderr.writeLine('= onResourceError()'); | |
system.stderr.writeLine(' - unable to load url: "' + resourceError.url + '"'); | |
system.stderr.writeLine(' - error code: ' + resourceError.errorCode + ', description: ' + resourceError.errorString ); | |
}; | |
page.onError = function(msg, trace) { | |
system.stderr.writeLine('= onError()'); | |
var msgStack = [' ERROR: ' + msg]; | |
if (trace) { | |
msgStack.push(' TRACE:'); | |
trace.forEach(function(t) { | |
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : '')); | |
}); | |
} | |
system.stderr.writeLine(msgStack.join('\n')); | |
}; | |
page.open('http://tumblr.com', function(status, b, c) { | |
page.render('example.png'); | |
console.log("DONE WITH ", status, page); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment