PHP code example of fyrts / chrome-devtools-protocol
1. Go to this page and download the library: Download fyrts/chrome-devtools-protocol 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/ */
fyrts / chrome-devtools-protocol example snippets
// context creates deadline for operations
$ctx = Context::withTimeout(Context::background(), 30 /* seconds */);
// launcher starts chrome process ($instance)
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
// work with new tab
$tab = $instance->open($ctx);
$tab->activate($ctx);
$devtools = $tab->devtools();
try {
$devtools->page()->enable($ctx);
$devtools->page()->navigate($ctx, NavigateRequest::builder()->setUrl("https://www.google.com/")->build());
$devtools->page()->awaitLoadEventFired($ctx);
// ... work with page ...
// e.g.
// - print to PDF: $devtools->page()->printToPDF($ctx, PrintToPDFRequest::make());
// - capture screenshot: $devtools->page()->captureScreenshot($ctx, CaptureScreenshotRequest::builder()->setFormat("jpg")->setQuality(95)->build());
} finally {
// devtools client needs to be closed
$devtools->close();
}
} finally {
// process needs to be killed
$instance->close();
}
$ctx = Context::withTimeout(Context::background(), 10);
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
$session = $instance->createSession($ctx);
try {
// $session implements DevtoolsClientInterface, same as returned from Tab::devtools()
} finally {
$session->close();
}
} finally {
$instance->close();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.