Skip to content

Commit

Permalink
allow setting cookie session=false
Browse files Browse the repository at this point in the history
Previously
```php
$page->setCookies([
    \HeadlessChromium\Cookies\Cookie::create("session_false", "session_false", ["session" => false, "domain" => "example.com"]),
    \HeadlessChromium\Cookies\Cookie::create("session_true", "session_true", ["session" => true, "domain" => "example.com"]),
])->await();
```
would create 2 cookies with session=true, but now it will create 1 cookie with session=false and 1 with session=true

close GH-675
  • Loading branch information
divinity76 authored Jan 7, 2025
1 parent 8a6052c commit 3537f34
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,12 @@ public function setCookies($cookies)
$browserCookie['domain'] = \parse_url($this->getCurrentUrl(), \PHP_URL_HOST);
}

// convinience wrapper for session=false
// DevTools Protocol does not allow setting session=false directly, but it will be set to false if expires is set
if (!isset($cookie['expires']) && ($cookie['session'] ?? null) === false) {
$browserCookie['expires'] = time() + (1 * 60 * 60 * 24 * 365); // the max expire chromium allows, 365 days, tested on chromium 131.0.6778.139
}

$browserCookies[] = $browserCookie;
}

Expand Down

0 comments on commit 3537f34

Please sign in to comment.