/
ChromeDevToolsDriver.php
46 lines (39 loc) · 1.11 KB
/
ChromeDevToolsDriver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Facebook\WebDriver\Chrome;
use Facebook\WebDriver\Remote\RemoteWebDriver;
/**
* Provide access to Chrome DevTools Protocol (CDP) commands via HTTP endpoint of Chromedriver.
*
* @see https://chromedevtools.github.io/devtools-protocol/
*/
class ChromeDevToolsDriver
{
const SEND_COMMAND = [
'method' => 'POST',
'url' => '/session/:sessionId/goog/cdp/execute',
];
/**
* @var RemoteWebDriver
*/
private $driver;
public function __construct(RemoteWebDriver $driver)
{
$this->driver = $driver;
}
/**
* Executes a Chrome DevTools command
*
* @param string $command The DevTools command to execute
* @param array $parameters Optional parameters to the command
* @return array The result of the command
*/
public function execute($command, array $parameters = [])
{
$params = ['cmd' => $command, 'params' => (object) $parameters];
return $this->driver->executeCustomCommand(
self::SEND_COMMAND['url'],
self::SEND_COMMAND['method'],
$params
);
}
}