Download the PHP package infostars/headless-chromium-php without Composer

On this page you can find all versions of the php package infostars/headless-chromium-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package headless-chromium-php

Chrome PHP

Build Status Latest Stable Version License

This library lets you start playing with chrome/chromium in headless mode from PHP.

/!\ The library is still young and some features you need might be missing. We add feature as feature requests are submitted, feel free to rise an issue if you want to see a new feature to be supported by the library. Additionally the library follows semver. That means that until version 1.0.0 a lot of changes might occur.

Features

Happy browsing!

Requirements

Requires php 5.6 and a chrome/chromium executable.

As of version 65 of chrome/chromium the library proved to work correctly. Please try to keep using latest version of chrome.

Note that the library is only tested on linux but is compatible with osX and windows.

Install

The library can be installed with composer and is available on packagist under infostars/headless-chromium-php

composer require infostars/headless-chromium-php

Usage

It uses a simple and understandable API to start chrome, to open pages, to take screenshots, to crawl websites... and almost everything that you can do with chrome as a human.

Using different chrome executable

When starting the factory will look for the environment variable "CHROME_PATH" to find the chrome executable. If the variable is not found then it will use "chrome" as the executable.

You can use any executable of your choice. For instance "chromium-browser":

Debugging

The following example adds some development-oriented features to help debugging

About debugLogger: this can be any of a resource string, a resource or an object implementing LoggerInterface from Psr\Log (such as monolog or apix/log).


API

Browser Factory

Options

Here are the options available for the browser factory:

Option name Default Description
connectionDelay 0 Delay to apply between each operation for debugging purposes
customFlags none Array of flags to pass to the command line. Eg: ['--option1', '--option2=someValue']
debugLogger null A string (e.g "php://stdout"), or resource, or PSR-3 logger instance to print debug messages
enableImages true Toggles loading of images
headless true Enable or disable headless mode
ignoreCertificateErrors false Set chrome to ignore ssl errors
keepAlive true true to keep alive the chrome instance when the script terminates
noSandbox false Useful to run in a docker container
sendSyncDefaultTimeout 3000 Default timeout (ms) for sending sync messages
startupTimeout 30 Maximum time in seconds to wait for chrome to start
userAgent none User agent to use for the whole browser (see page api for alternative)
userDataDir none chrome user data dir (default: a new empty dir is generated temporarily)
windowSize none Size of the window. usage: [$width, $height] - see also Page::setViewportSize

Browser API

Create a new page (tab)

Close the browser

Set a script to evaluate before every page created by this browser will navigate

Page API

Navigate to an url

When Using $navigation->waitForNavigation() you will wait for 30sec until the page event "loaded" is triggered. You can change the timeout or the event to listen for:

Available events (in the order they trigger):

When you want to wait for the page to navigate there are 2 main issues that may occur. First the page is too long to load and second the page you were waiting to be loaded has been replaced. The good news is that you can handle those issues using a good old try catch:

Evaluate script on the page

Once the page has completed the navigation you can evaluate arbitrary script on this page:

Sometime the script you evaluate will click a link or submit a form, in this case the page will reload and you will want to wait for the new page to reload.

You can achieve this by using $page->evaluate('some js that will reload the page')->waitForPageReload(). An example is available in form-submit.php

Call a function

This is an alternative to evaluate that allows to call a given function with the given arguments in the page context:

Add a script tag

That's useful if you want to add jQuery (or anything else) to the page:

You can also use an url to feed the src attribute:

Add a script to evaluate upon page navigation

If your script needs the dom to be fully populated before it runs then you can use the option "onLoad":

Set viewport size

This features allows to change the size of the viewport (emulation) for the current page without affecting the size of all the browser's pages (see also option "windowSize" of BrowserFactory::createBrowser).

Make a screenshot

choose an area

You can use the option "clip" in order to choose an area for the screenshot (TODO exemple)

take a full page screenshot

You can also take a screenshot for the full layout (not only the layout) using $page->getFullPageClip (TODO exemple)

TODO Page.getFullPageClip();

Print as PDF

Mouse API

The mouse API is dependent on the page instance and allows you to control the mouse's moves and clicks.

Cookie API

You can set and get cookies for a page:

Set Cookie

Get Cookies

Set user agent

You can set an user agent per page :

See also BrowserFactory option userAgent to set it for the whole browser.


Advanced usage

The library ships with tools that hide all the communication logic but you can use the tools used internally to communicate directly with chrome debug protocol.

Example:

Create a session and send message to the target

Debugging

You can ease the debugging by setting a delay before each operation is made:

Browser (standalone)

Contributing

See CONTRIBUTING.md for contribution details.

Credits

Thanks to puppeteer that served as an inspiration.

Roadmap

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Fair License.


All versions of headless-chromium-php with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
symfony/process Version ^3|^4
wrench/wrench Version ^2.0
symfony/filesystem Version ^3|^4
psr/log Version ^1.0
apix/log Version ^1.2
evenement/evenement Version ~v2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package infostars/headless-chromium-php contains the following files

Loading the files please wait ....