|
13 | 13 |
|
14 | 14 | namespace Symfony\Component\Panther;
|
15 | 15 |
|
| 16 | +use Facebook\WebDriver\Exception\InvalidArgumentException; |
16 | 17 | use Facebook\WebDriver\Exception\NoSuchElementException;
|
17 | 18 | use Facebook\WebDriver\Exception\TimeoutException;
|
18 | 19 | use Facebook\WebDriver\JavaScriptExecutor;
|
|
35 | 36 | use Symfony\Component\DomCrawler\Crawler;
|
36 | 37 | use Symfony\Component\DomCrawler\Form;
|
37 | 38 | use Symfony\Component\DomCrawler\Link;
|
| 39 | +use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse; |
38 | 40 | use Symfony\Component\Panther\Cookie\CookieJar;
|
39 | 41 | use Symfony\Component\Panther\DomCrawler\Crawler as PantherCrawler;
|
40 | 42 | use Symfony\Component\Panther\DomCrawler\Form as PantherForm;
|
@@ -143,7 +145,7 @@ public function getRequest(): object
|
143 | 145 |
|
144 | 146 | public function getResponse(): object
|
145 | 147 | {
|
146 |
| - throw new \LogicException('HttpFoundation Response object is not available when using WebDriver.'); |
| 148 | + return $this->response ?? throw new \LogicException('HttpFoundation Response object is not available when using WebDriver.'); |
147 | 149 | }
|
148 | 150 |
|
149 | 151 | public function followRedirects($followRedirects = true): void
|
@@ -527,8 +529,35 @@ public function get($url): self
|
527 | 529 |
|
528 | 530 | $this->internalRequest = new Request($url, 'GET');
|
529 | 531 | $this->webDriver->get($url);
|
| 532 | + |
| 533 | + if ($this->webDriver instanceof JavaScriptExecutor) { |
| 534 | + $this->executeScript('window.localStorage.setItem("symfony/profiler/toolbar/displayState", "none");'); |
| 535 | + } |
| 536 | + |
530 | 537 | $this->internalResponse = new Response($this->webDriver->getPageSource());
|
531 | 538 |
|
| 539 | + if ($this->browserManager instanceof ChromeManager) { |
| 540 | + try { |
| 541 | + $events = $this->webDriver->manage()->getLog('performance'); |
| 542 | + } catch (InvalidArgumentException) { |
| 543 | + $events = []; |
| 544 | + } |
| 545 | + |
| 546 | + foreach ($events as $event) { |
| 547 | + $event = json_decode($event['message'], true)['message']; |
| 548 | + |
| 549 | + if ('Network.responseReceived' !== ($event['method'] ?? '')) { |
| 550 | + continue; |
| 551 | + } |
| 552 | + $response = $event['params']['response']; |
| 553 | + |
| 554 | + if ($response['url'] === $url) { |
| 555 | + $this->response = new HttpFoundationResponse($this->internalResponse->getContent(), $response['status'], $response['headers']); |
| 556 | + break; |
| 557 | + } |
| 558 | + } |
| 559 | + } |
| 560 | + |
532 | 561 | $this->crawler = $this->createCrawler();
|
533 | 562 |
|
534 | 563 | return $this;
|
|
0 commit comments