dzentota/chrome-dev-tools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dzentota/chrome-dev-tools

Composer 安装命令:

composer require dzentota/chrome-dev-tools

包简介

This is a PHP lib that allows one to interact with Google Chrome using Chrome DevTools Protocol within a PHP script. Highly inspired by marty90/PyChromeDevTools

README 文档

README

1. Description

This is a PHP lib that allows one to interact with Google Chrome using Chrome DevTools Protocol within a PHP script. To use this tool, you must run an instance of Google Chrome with the remote-debugging option, like in the following example.

google-chrome --remote-debugging-port=9222

You may want to enable further Chrome benchmarking capabilities using the --enable-benchmarking and --enable-net-benchmarking options. You can run Chrome in headless mode using the option --headless.

2. Prerequisites

An updated Google-Chrome version

3. Operation

3.1 Init

In your php script, as first, you must create a Chrome object, like in the following:

$chrome = new ChromeDevTools\Chrome();

You can specify the host and the port of Chrome manually writing:

$chrome = new ChromeDevTools\Chrome($host="1.1.1.1", $port=1234);

By default it uses localhost:9222.

3.1 Run commands

To send a command to Chrome, just invoke the corresponding method on the Chrome object, and pass the desired parameters. For example, to visit a page write:

$chrome->Page->navigate(['url' => 'http://example.com/']);

The return value of the command is passed as return value of the function, already interpreted as JSON.

3.1 Receive Events

Chrome sends back messages for particular events in the browser. You can get them in two ways; they are returned already interpreted as JSON. All unread events are erased before any new command is run.

a) You can pop one message from the queue of received ones writing:

$message = $chrome->waitMessage();

The method accepts an optional parameter timeout which is the value in seconds after which it gives up and returns null. Default is 1.

b) You can wait for a specific event writing:

$result = $chrome->waitEvent('event_name');
$matchingEvent = $result['matching_message'];
$messages = $result['messages'];

It waits until an event with the name event_name arrives, or a timeout elapses. $matchingEvent contains the first found event that has event_name, while $messages contains all messages arrived before. Timeout value can be configured as in the previous method.

4. Examples

@See examples folder

dzentota/chrome-dev-tools 适用场景与选型建议

dzentota/chrome-dev-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.46k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2017 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dzentota/chrome-dev-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dzentota/chrome-dev-tools 我们能提供哪些服务?
定制开发 / 二次开发

基于 dzentota/chrome-dev-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

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