Storage

Set Storage

Writes or updates a value in whichever storage the storageType names: cookie, localStorage, sessionStorage, cache, or indexedDb. One route serves all of them, and what has to be supplied depends on which one you picked. localStorage and sessionStorage are plain key and value pairs, so storageType, key, and data are all that is mandatory, with domain and path optional. Cache Storage also needs storeName, the cache name, with the key acting as the request. IndexedDB needs both storeName, the object store, and path, the database name, with the key identifying the record.

NOTE

The extra mandatory parameters for cache and IndexedDB are enforced when the call is validated, which is why a storage write that works for localStorage can be rejected for IndexedDB with the same shape of call.

Parameter Cookies LocalStorage SessionStorage Cache Storage IndexedDB
Domain action.Domain (implicit current origin) (implicit current origin) (implicit current origin) (unused, origin-scoped)
Path action.Path (cookie path) (unused) (unused) (unused) action.Path (database name)
StoreName (unused) (unused) (unused) action.StoreName (cache name) action.StoreName (object store)
Key action.Key (cookie name) action.Key action.Key action.Key (cache name / request) action.Key (record key)
Wildcard allowed? Domain, Path, Key Key only Key only StoreName, Key Path, StoreName, Key

Examples

GPAL Fluent: High-level fluent C# API

//Two halves. The url says what storage this workflow touches, and RunSet only ever picks from what was declared there, so a url with nothing declared writes nothing and says nothing. The WithStorage calls on the browser are filters naming which of the declared actions to run, and WithStorageData carries the value. The filters stay set until an action runs, and the first WithStorage call after that clears them and starts again, so each block reads as one statement.

// declared on the url, before you navigate. these are the actions that will be in play

GPALUrl youtube = "www.youtube.com";


youtube.WithStorageType(WebsiteStorageType.cookie)

.WithStorageDomain("youtube.com")

.WithStorageKey("VISITOR_PRIVACY_METADATA");


youtube.WithStorageType(WebsiteStorageType.localStorage)

.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY");


browser.GoTo(youtube);


// called inline, naming which of them to run and what to write

browser.WithStorageDomain("youtube.com")

.WithStorageKey("VISITOR_PRIVACY_METADATA")

.WithStorageData("hello there")

.RunSet(WebsiteStorageType.cookie);

MagicHelper: MagicHelper utility library

browser.MagicHelper.SetStorage(WebsiteStorageType.localStorage, data, domain: "ebay.com", key: "u_sclid");

browser.MagicHelper.SetStorage(WebsiteStorageType.cache, data, key: "/api/data", storeName: "my-cache");

browser.MagicHelper.SetStorage(WebsiteStorageType.indexedDb, data, path: "myDatabase", key: "record1", storeName: "myObjectStore");

Puppeteer Client: Puppeteer-style C# client

browser.PuppeteerClient.SetStorage(WebsiteStorageType.localStorage)

.WithStorageDomain("ebay.com").WithStorageKey("u_sclid").WithStorageData(data).Execute();

Puppeteer Communicator: Low-level communicator

await browser.PuppeteerCommunicator.SetStorage(string storageType, string sessionId, string domain, string key, string data, string storeName, string path);

REST Client: Direct REST/HTTP client

//The REST client names the value WithData. PuppeteerClient names the same thing WithStorageData.

// localStorage: key and data are enough

browser.OttoMagicClient.SetStorage(WebsiteStorageType.localStorage)

.WithStorageDomain("ebay.com").WithStorageKey("u_sclid").WithData(data).Execute();


// cache: the cache name goes in storeName, the request in key

browser.OttoMagicClient.SetStorage(WebsiteStorageType.cache)

.WithStorageStoreName("my-cache").WithStorageKey("/api/data").WithData(data).Execute();


// indexedDb: database in path, object store in storeName, record in key

browser.OttoMagicClient.SetStorage(WebsiteStorageType.indexedDb)

.WithStoragePath("myDatabase").WithStorageStoreName("myObjectStore")

.WithStorageKey("record1").WithData(data).Execute();

💬 Ask GPAL