From 69e41da0318fc528cf3b44bb526fa0e9bcc5655a Mon Sep 17 00:00:00 2001 From: waahhhh <40632052+waahhhh@users.noreply.github.com> Date: Tue, 24 Jun 2025 21:23:20 +0200 Subject: [PATCH] custom referrer --- src/Page.php | 4 ++-- src/PageUtils/PageNavigation.php | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Page.php b/src/Page.php index 8a04f83..d09eff1 100644 --- a/src/Page.php +++ b/src/Page.php @@ -211,7 +211,7 @@ public function setExtraHTTPHeaders(array $headers = []): void /** * @param string $url * @param array $options - * - strict: make waitForNAvigation to fail if a new navigation is initiated. Default: false + * @see https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-navigate for available options * * @throws CommunicationException * @@ -221,7 +221,7 @@ public function navigate(string $url, array $options = []) { $this->assertNotClosed(); - return new PageNavigation($this, $url, $options['strict'] ?? false); + return new PageNavigation($this, $url, $options); } /** diff --git a/src/PageUtils/PageNavigation.php b/src/PageUtils/PageNavigation.php index d95cfe1..d428f6e 100644 --- a/src/PageUtils/PageNavigation.php +++ b/src/PageUtils/PageNavigation.php @@ -67,15 +67,22 @@ class PageNavigation * * @param Page $page * @param string $url - * @param bool $strict by default this method will wait for the page to load even if a new navigation occurs - * (ie: a new loader replaced the initial navigation). Passing $string to true will make the navigation to fail - * if a new loader is generated - * + * @param array{ + * // by default this method will wait for the page to load even if a new navigation occurs + * // (ie: a new loader replaced the initial navigation). Passing strict to true will make the navigation to fail + * // if a new loader is generated + * strict?: bool, + * transitionType?: string, + * frameId?: string, + * referrer?: string, + * referrerPolicy?: string, + * // for more options checkout the documentation https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-navigate + * } $options * @throws Exception\CommunicationException * @throws Exception\CommunicationException\CannotReadResponse * @throws Exception\CommunicationException\InvalidResponse */ - public function __construct(Page $page, string $url, bool $strict = false) + public function __construct(Page $page, string $url, array $options = []) { // make sure latest loaderId was pulled $page->getSession()->getConnection()->readData(); @@ -83,15 +90,18 @@ public function __construct(Page $page, string $url, bool $strict = false) // get previous loaderId for the navigation watcher $this->previousLoaderId = $page->getFrameManager()->getMainFrame()->getLatestLoaderId(); + $params = array_merge(['url' => $url], $options); + unset($params['strict']); + // send navigation message $this->navigateResponseReader = $page->getSession()->sendMessage( - new Message('Page.navigate', ['url' => $url]) + new Message('Page.navigate', $params) ); $this->page = $page; $this->frame = $page->getFrameManager()->getMainFrame(); $this->url = $url; - $this->strict = $strict; + $this->strict = $options['strict'] ?? false; } /**