PHP code example of milivojsa / laravel-chrome

1. Go to this page and download the library: Download milivojsa/laravel-chrome library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

milivojsa / laravel-chrome example snippets


/*
|--------------------------------------------------------------------------
| Chrome Path
|--------------------------------------------------------------------------
|
| Manually set the path where Google Chrome is installed.
|
*/
'exec_path' => '/path/to/chrome',

/*
|--------------------------------------------------------------------------
| User Agent
|--------------------------------------------------------------------------
|
| Change the user agent that will be used by Google Chrome.
|
*/
'user_agent' => 'nice-user-agent',

/*
|--------------------------------------------------------------------------
| Timeout
|--------------------------------------------------------------------------
|
| Specify a timeout in seconds.
| (null = no timeout)
|
*/
'timeout' => 10,

/*
|--------------------------------------------------------------------------
| Viewport
|--------------------------------------------------------------------------
|
| Specify a viewport.
|
*/
'viewport' => [
                    'width' => 1920,
                    'height' => 1080
                ],

/*
|--------------------------------------------------------------------------
| Blacklist
|--------------------------------------------------------------------------
|
| Specify a list of files that should not be loaded.
|
*/
'blacklist' => [
                    'www.google-analytics.com',
                    'analytics.js'
                ],

/*
|--------------------------------------------------------------------------
| Additional Request Headers
|--------------------------------------------------------------------------
|
| Specify additional headers.
|
*/
'headers' => [
                'DNT' => 1 // DO NOT TRACK
             ],

use ChromeHeadless\Laravel\ChromeHeadless;

$html = ChromeHeadless::url('https://example.com')->getHtml();

use ChromeHeadless\Laravel\ChromeHeadless;

$dom = ChromeHeadless::url('https://example.com')->getDOMCrawler();
    
$title = $dom->filter('title')->text();
bash
php artisan vendor:publish --provider="ChromeHeadless\ChromeHeadlessServiceProvider"