Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 40d375a

Browse files
committed
Do not fail getCookies in Microsoft Edge if there are no cookies
1 parent dd1313f commit 40d375a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
1818

1919
### Fixed
2020
- `WebDriverExpectedCondition::presenceOfElementLocated()` works correctly when used within `WebDriverExpectedCondition::not()`.
21+
- Improper behavior of Microsoft Edge when retrieving all cookies via `getCookies()` (it was causing fatal error when there were no cookies).
2122

2223
## 1.7.1 - 2019-06-13
2324
### Fixed

lib/WebDriverOptions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public function getCookieNamed($name)
107107
[':name' => $name]
108108
);
109109

110+
if (!is_array($cookieArray)) { // Microsoft Edge returns null even in W3C mode => emulate proper behavior
111+
throw new NoSuchCookieException('no such cookie');
112+
}
113+
110114
return Cookie::createFromArray($cookieArray);
111115
}
112116

@@ -128,8 +132,11 @@ public function getCookieNamed($name)
128132
public function getCookies()
129133
{
130134
$cookieArrays = $this->executor->execute(DriverCommand::GET_ALL_COOKIES);
131-
$cookies = [];
135+
if (!is_array($cookieArrays)) { // Microsoft Edge returns null if there are no cookies...
136+
return [];
137+
}
132138

139+
$cookies = [];
133140
foreach ($cookieArrays as $cookieArray) {
134141
$cookies[] = Cookie::createFromArray($cookieArray);
135142
}

0 commit comments

Comments
 (0)