Class: Playwright::WebStorage

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/web_storage.rb,
sig/playwright.rbs

Overview

WebStorage exposes the page's localStorage or sessionStorage for the current origin via an async, browser-consistent API.

Instances are accessed through [property: Page.localStorage] and [property: Page.sessionStorage].

page.goto("https://example.com")
page.local_storage.set_item("token", "abc")
token = page.local_storage.get_item("token")
all = page.local_storage.items()
page.local_storage.remove_item("token")
page.local_storage.clear()

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#clearvoid

This method returns an undefined value.

Removes all items from the storage.



44
45
46
# File 'lib/playwright_api/web_storage.rb', line 44

def clear
  wrap_impl(@impl.clear)
end

#get_item(name) ⇒ nil, String

Returns the value for the given name if present.

Parameters:

  • name (String)

Returns:

  • (nil, String)


26
27
28
# File 'lib/playwright_api/web_storage.rb', line 26

def get_item(name)
  wrap_impl(@impl.get_item(unwrap_impl(name)))
end

#itemsArray[untyped]

Returns all items in the storage as name/value pairs.

Returns:

  • (Array[untyped])


20
21
22
# File 'lib/playwright_api/web_storage.rb', line 20

def items
  wrap_impl(@impl.items)
end

#remove_item(name) ⇒ void

This method returns an undefined value.

Removes the item with the given name. No-op if the item is absent.

Parameters:

  • name (String)


38
39
40
# File 'lib/playwright_api/web_storage.rb', line 38

def remove_item(name)
  wrap_impl(@impl.remove_item(unwrap_impl(name)))
end

#set_item(name, value) ⇒ void

This method returns an undefined value.

Sets the value for the given name. Overwrites any existing value for that name.

Parameters:

  • name (String)
  • value (String)


32
33
34
# File 'lib/playwright_api/web_storage.rb', line 32

def set_item(name, value)
  wrap_impl(@impl.set_item(unwrap_impl(name), unwrap_impl(value)))
end