Search code examples
laravellaravel-dusk

Interact with localStorage in Laravel Dusk


I’m trying to get with the help of Laravel Dusk

The value of localStorage

I tried the following variation

$value = $browser->value('localStorage.getItem("SKU")');
$value = $browser->text('localStorage.getItem("SKU")');

dd($browser->assertSeeIn("localStorage.getItem('SKU')"))

All of them throwback an error. Are there any other options?


Solution

  • Use script() to execute JavaScript and return values:

    $value = $browser->script("return localStorage.getItem('SKU')")[0];