Automation Targets

Browser Storage: Defining and Running Storage Actions

GPALUrl carries a list of storage actions -- cookies, localStorage, sessionStorage, indexedDb, and cache -- to inspect or change once that URL is active. The With...() calls used to define those actions on the GPALUrl double as filters when called on the browser before RunGet/RunSet/RunDelete, and WithUserDefined gives you a fallback when the built-in fields cannot pin down the action you mean.

Defining Storage Actions on a GPALUrl

A GPALUrl can carry a list of storage actions describing browser storage to inspect or modify. Cookies, localStorage, sessionStorage, indexedDb, or cache. Once that URL becomes the active page. WithStorageType(type) starts a new action definition; the With...() calls that follow (WithStorageDomain, WithStoragePath, WithStorageKey, WithStorageStoreName, and WithStorageData) configure that definition and only that definition. Calling WithStorageType again starts the next one. These are definitions, not instructions to run yet; nothing happens until the URL is visited and the browser is told which of its defined actions to run.

GPALUrl youtubeUrl = "www.youtube.com";

youtubeUrl

.WithStorageType(WebsiteStorageType.cookie)

.WithStorageDomain("youtube.com")

.WithStorageKey("VISITOR_PRIVACY_METADATA");

youtubeUrl

.WithStorageType(WebsiteStorageType.localStorage)

.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY");

browser.GoTo(youtubeUrl).WaitFor(3_000);

Running Storage Actions: With...() as Filters

Once a GPALUrl is active (after GoTo or Get), RunGet, RunSet, and RunDelete execute against the storage actions defined on that URL. The same With...() calls used to define actions on a GPALUrl also work directly on the browser as filters, narrowing which defined actions the Run call applies to. Filters stay in effect across multiple runs. The next With...() call after a Run starts a fresh unit of work.

browser

.WithStorageDomain("youtube.com")

.WithStorageKey("VISITOR_PRIVACY_METADATA")

.RunGet(WebsiteStorageType.cookie)

.GetStorageData(out string cookieValue);

browser

.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY")

.WithStorageData("{"hasSucceededOnce":false}")

.RunSet(WebsiteStorageType.localStorage);

TIP

RunGet, RunSet, and RunDelete do not reset the filters. The current filter values stay in play until you call a With...() method after a run, which begins a new StorageAction. You only need to re-set filter values when they actually change between runs.

When Filters Aren't Enough: WithUserDefined

Domain, path, key, and store name do not always uniquely identify an action. Two actions on the same GPALUrl might share all of them, or the thing you are targeting (a cache entry, an indexedDb record) might not map cleanly onto those fields at all. WithUserDefined(tag) tags an action with an arbitrary string when it is defined on the GPALUrl, and WithUserDefinedFilter(tag) on the browser selects actions by that tag instead of, or in addition to, the standard fields. Treat it as an escape hatch: a label you invent yourself so a RunGet, RunSet, or RunDelete call can find the right action when the built-in filters cannot.

youtubeUrl

.WithStorageType(WebsiteStorageType.cache)

.WithStorageStoreName("yt-icons")

.WithUserDefined("icon-cache");

browser

.WithUserDefinedFilter("icon-cache")

.RunGet(WebsiteStorageType.cache)

.GetStorageData(out string iconData);