Accessing windows.localStorage with PuppeteerSharp

Viewed 343

Does anyone provide an example of how to access windows.localStorage using PuppeteerSharp?
There are lots of examples of how to do it using (JS)Puppeteer, but I'm having problems doing it in C#.

As far as I can tell, I need to use EvaluateFunctionAsync, and do something like the following:
var localStorage = await page.EvaluateFunctionAsync("async () => await window.localStorage");
But this just returns an empty JToken.
Can anyone help me out?

1 Answers

Got it:
var localStorage = await page.EvaluateFunctionAsync<Dictionary<string, string>>("async () => Object.assign({}, window.localStorage)");

Related