symfony / panther

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

What about the Chrome DevTools Protocol ? #78

Open maidmaid opened 5 years ago

maidmaid commented 5 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 5 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 5 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 5 years ago

@maidmaid Could you provide an example, please?

maidmaid commented 5 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