- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
PhantomJS - onError()
The OnError() method is called when there is a JavaScript error. The arguments for the onError method are msg and stack trace, which is an array.
Syntax
Its syntax is as follows −
page.onError = function(msg, trace) {}
Example
The following code shows the use of onError() method.
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/test.html', function(status) { phantom.exit(); });
test.html
<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>
The above program generates the following output.
CONSOLE Message: ReferenceError: Can't find variable: page [{"file":"http://localhost/tasks/test.html","line":8,"function":"onload"}]
phantomjs_webpage_module_events_callbacks.htm
Advertisements