You are currently viewing version 4.0 documentation.


PhantomJS log

Verbose logging can be enabled for PhantomJS by setting the debug flag on the client. This is the same as setting the PhantomJS --debug=true command line option.

        
    <?php 
    
    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();
    $client->getEngine()->debug(true);

The client log can be inspected after making a request.

        
    <?php 
    
    ...
    
    $client->getLog(); // String
    
    ...

Note

The client log contains some helpful information specific to the PhantomJS library. In some cases these are present in the log even if debugging is disabled.

Javascript console log

The response object also provides access to a console log. Any javascript errors raised on the requested page will be present in the response console log.

        
    <?php 
    
    ...
    
    $response->getConsole(); // Array
    
    ...

Validation errors

Before a script template is compiled and cached it is validated using the Esprima javascript validation engine. If the script fails to validate then a JonnyW\PhantomJs\Exception\SyntaxException will be raised. Debug information about any validation errors can be found by calling a getErrors() helper method on the exception instance. This will return an array of error information.

    <?php 
    
    // $exception->getErrors();    
    array(1) {
      array(5) {
        'lineNumber'  => 1,
        'column'      => 17,
        'index'       => 16,
        'description' => 'Unexpected token ;',
        'message'     => 'Line 1: Unexpected token ;'
      }
    }

Important

Due to a limitation in the validation logic, scripts are currently minified to a single line before validating. This makes the lineNumber value contained in the error output redundant. This is due to be fixed in a future release.