GPALUrl carries storage definitions - cookies, localStorage, sessionStorage, cache, and indexedDb - that you describe up front with WithStorageType and friends, then execute against the active browser with RunGet, RunSet, and RunDelete. This tutorial walks a cookie and a localStorage entry through a full get/set/delete cycle, then shows how the same verbs extend to indexedDb.
Here's the whole workflow, start to finish. Each piece is broken down and explained below.
using GenerallyPositive;
using GenerallyPositive.Browser;
using static GenerallyPositive.Enums;
GPAL
.WithPublishToConsole()
.WithDriverLocation(@"C:drivers")
.WithUseOttoMagic(@"C:OttoMagic");
IBrowser browser = GPAL.Browser
.WithBrowserType(BrowserType.Chrome)
.WithUseAutomationEngine(AutomationEngine.OttoMagic)
.ToGPALObject();
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);
string outData;
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.RunGet(WebsiteStorageType.cookie)
.GetStorageData(out outData);
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.WithStorageData("hello there")
.RunSet(WebsiteStorageType.cookie);
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.RunDelete(WebsiteStorageType.cookie);
browser
.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY")
.RunGet(WebsiteStorageType.localStorage)
.GetStorageData(out outData);
browser
.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY")
.WithStorageData("{"data":{"hasSucceededOnce":false}}")
.RunSet(WebsiteStorageType.localStorage);
browser
.WithStorageKey("ytidb::LAST_RESULT_ENTRY_KEY")
.RunDelete(WebsiteStorageType.localStorage);
browser.Close(true);
youtubeUrl is a GPALUrl - assign it from a string and it reads like one, but it can also carry storage definitions you attach before ever navigating. Each WithStorageType call describes what to look at later: a cookie named VISITOR_PRIVACY_METADATA on youtube.com, and a localStorage entry named ytidb::LAST_RESULT_ENTRY_KEY. Neither line performs an action yet - they just describe targets.
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);
Once you GoTo (or Get) a GPALUrl, it becomes the browser's active URL - and the storage definitions attached to it are what RunGet, RunSet, and RunDelete operate against for the rest of the workflow. See Value Objects: More Than a String.
WithStorageDomain and WithStorageKey narrow which definition to act on - useful once a URL has more than one. RunGet(cookie) executes the read against the live browser, and GetStorageData(out outData) copies the result into a variable you can use however you like.
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.RunGet(WebsiteStorageType.cookie)
.GetStorageData(out outData);
RunSet and RunDelete follow the same shape as RunGet: set up the With* parameters that identify what you're targeting, supply WithStorageData for a write, then call the Run* verb for the storage type you're working with.
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.WithStorageData("hello there")
.RunSet(WebsiteStorageType.cookie);
browser
.WithStorageDomain("youtube.com")
.WithStorageKey("VISITOR_PRIVACY_METADATA")
.RunDelete(WebsiteStorageType.cookie);
Once a RunGet, RunSet, or RunDelete call executes, the With* parameters that scoped it are cleared. If your next Run* call needs the same domain, key, path, or store name, set them again with With* first - otherwise that call falls back to its broadest scope.
WebsiteStorageType has five values - cookie, localStorage, sessionStorage, cache, and indexedDb - and all five use the same WithStorageType / RunGet / RunSet / RunDelete / GetStorageData verbs. cache and indexedDb add WithStorageStoreName (and, for indexedDb, WithStoragePath for the database name) to address a specific store inside the browser's structured storage, but the pattern doesn't change.
youtubeUrl.WithStorageType(WebsiteStorageType.indexedDb)
.WithStoragePath("YtIdbMeta") // database name
.WithStorageStoreName("databases") // object store within that database
.WithStorageKey("ServiceWorkerLogsDatabase");
browser
.WithStoragePath("YtIdbMeta")
.WithStorageStoreName("databases")
.WithStorageKey("ServiceWorkerLogsDatabase")
.RunGet(WebsiteStorageType.indexedDb)
.GetStorageData(out outData);
Whether you're clearing a single cookie or reading an entry out of a nested indexedDb object store, the workflow is always: describe it with WithStorageType and its With* parameters, then act on it with RunGet, RunSet, or RunDelete.
Showing off some plain text in these paragraphs eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Here you can find different accents and emphasis sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
This is a link and how it could look like bestlinkinthebeautifulworld. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Here's just some classic bold text adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam notBoldSecondbestlinkinthebeautifulworld illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at adipisicing elit libero vel voluptas? Expedita, adipisicing facere dolores voluptatem ad ab rem assumenda soluta!
Other cuple of colors in case we want to emphasize several ways adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at voluptatem libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae quas consequuntur illo numquam assumenda autem exercitationem distinctio perspiciatis in natus. Eius dicta similique ipsam ipsa minima, nemo quae enim tempore.
GPAL
.CallIfNotFound(GenericCallIfNotFound)
.WithPublishToConsole();
//System.Drawing.Rectangle windowSize = new System.Drawing.Rectangle(10, 10, 1500, 1024);
// NOTE: we have to set browser = before we execute any steps
// this is due to the 'GenericCallIfNotFound' which might throw an exception, and BankScraper will not have the browser set when it calls scraper.Close()
// until the complete fluent line gets executed (meaning every step, meaning browser is not set until everything else succeeds)
browser = GPAL.Browser
.WithBrowserType(Enums.BrowserType.Chrome)
.WithProfileDataDirectory(ChromeProfileLocation)
.WithUseAutomationEngine(AutomationEngine.Selenium)
.WithWindowSize(new System.Drawing.Rectangle(0,0,1920,1080))
.ToGPALObject();