GithubHelp home page GithubHelp logo

rvanweerd / chrome-dev-tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dzentota/chrome-dev-tools

0.0 2.0 0.0 14 KB

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

License: MIT License

PHP 100.00%

chrome-dev-tools's Introduction

chrome-dev-tools

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

chrome-dev-tools's People

Contributors

dzentota avatar

Watchers

 avatar  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.