From 0411bf5c8d82753ee78c86ec1d9ecab5c4ec4faa Mon Sep 17 00:00:00 2001 From: acoulton Date: Thu, 17 Oct 2024 13:05:06 +0100 Subject: [PATCH] Flush localstorage (temporarily merge #22 for our fork) Squashed commit of the following: commit fd1a98ba24422690cf5ac8ab6d45c3ff4db9217c Author: acoulton Date: Tue May 17 10:13:25 2022 +0100 Natively flush Chrome localstorage for the domain Now that the driver always starts on about:blank, it's not possible to use javascript to flush localstorage from a hook because it's not on the right domain. Fortunately devtools protocol exposes a command for this. --- CHANGELOG.md | 1 + src/ChromeDriver.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb9796..21105e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changelog ## 2.9.4.2 (CUSTOM INGENERATOR RELEASE) (2024-10-17) * Some minor connection enhancements #19 +* Support flushing localstorage for domain #22 ## 2.9.4.1 (CUSTOM INGENERATOR RELEASE) (2024-09-30) diff --git a/src/ChromeDriver.php b/src/ChromeDriver.php index 38667e0..c20a6d6 100644 --- a/src/ChromeDriver.php +++ b/src/ChromeDriver.php @@ -1743,4 +1743,15 @@ public function captureScreenshot($filename, $options = []) file_put_contents($filename, $imageData); } + + public function clearLocalStorageForOrigin(string $origin): void + { + $this->page->send( + 'Storage.clearDataForOrigin', + [ + 'origin' => $origin, + 'storageTypes' => 'local_storage', + ] + ); + } }