symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.95k stars 223 forks source link

What about the Chrome DevTools Protocol ? #78

Open maidmaid opened 6 years ago

maidmaid commented 6 years ago

The Chrome DevTools Protocol allows for tools to instrument, inspect, debug and profile Chromium, Chrome and other Blink-based browsers.

https://chromedevtools.github.io/devtools-protocol/

Basically, Chrome allows to be started with a --remote-debugging-port agument which gives access to the DevTools. That could significantly expand what we can do by manipulating for instance the Network panel in the DevTools. But maybe, integrating it in this project is off topic ?

dunglas commented 6 years ago

You can already pass arguments to the crime binary by setting them in ChromeManager::__construct(). It would be nice to addd a doc section about dev tools.

Also, if we can think to useful features leveraging this protocol, let’s add them as long as they don’t prevent using other browsers!

maidmaid commented 6 years ago

I found a solution without using the DevTools Protocol : enabling the performance log of the chrome driver.

ChromeDriver supports performance logging, from which you can get events of domains "Timeline", "Network", and "Page", as well as trace data for specified trace categories.

http://chromedriver.chromium.org/logging/performance-log

rocramer commented 6 years ago

@maidmaid Could you provide an example, please?

maidmaid commented 6 years ago

Between these 2 lines of code, add :

$perfLoggingPrefs = new \stdClass();
$perfLoggingPrefs->enableNetwork = true;
$chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);

$loggingPrefs = new \stdClass();
$loggingPrefs->performance = 'ALL';
$capabilities->setCapability('loggingPrefs', $loggingPrefs);

And then, you can do :

$logs = $client->getWebDriver()->manage()->getLog('performance');

cf https://github.com/facebook/php-webdriver/issues/551