Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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);
}

/**
Expand Down
24 changes: 17 additions & 7 deletions src/PageUtils/PageNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,41 @@ 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();

// 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;
}

/**
Expand Down