Coder Social home page Coder Social logo

geekwolverine / chrome-devtools-protocol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakubkulhan/chrome-devtools-protocol

0.0 1.0 0.0 3.47 MB

Chrome Devtools Protocol client for PHP

License: MIT License

Shell 0.02% PHP 99.93% Makefile 0.02% Dockerfile 0.03%

chrome-devtools-protocol's Introduction

Chrome Devtools Protocol PHP client

Build Latest Stable Version License

PHP client for Chrome Devtools Protocol.

Basic usage

// 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();
}

Headless Chrome isolated contexts

Headless Chrome supports feature called browser contexts - they're like incognito windows - cookies, local storage etc. are not shared. After browser context is destroyed, user data created in given context, are destroyed.

Unlike incognito windows, there can be multiple isolate browser contexts at the same time.

$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();
}

License

Licensed under MIT license. See LICENSE file.

chrome-devtools-protocol's People

Contributors

hongaar avatar jakubkulhan avatar janbukva avatar mikenz avatar mstyles avatar voldemortensen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.