承接 jakubkulhan/chrome-devtools-protocol 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jakubkulhan/chrome-devtools-protocol

最新稳定版本:v1.0.4

Composer 安装命令:

composer require jakubkulhan/chrome-devtools-protocol

包简介

Chrome Devtools Protocol client for PHP

README 文档

README

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

Using an already running Chrome browser

use ChromeDevtoolsProtocol\Instance\Instance;

$instance = new Instance(/* host: */ "localhost", /* port: */ 9222);


$ctx = Context::withTimeout(Context::background(), 30 /* seconds */);

$tab = $instance->open($ctx);
$tab->activate($ctx);

$devtools = $tab->devtools();

// ...work with devtools

// no need to call ->close() as no new process is started

License

Licensed under MIT license. See LICENSE file.

统计信息

  • 总下载量: 962.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 188
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 184
  • Watchers: 14
  • Forks: 50
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-21