You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current CookiePartitionKeyConverter doesn't currently support deserialization if the key is already a string. Essentially, trying to serialize these back out to a file, and then read back in again doesn't currently work, because the current writer writes as a string, and the reader will attempt to read an object. This currently works in puppeteer, because it's expecting an object from CDP, but it should still be able to deserialize if the cookies are offloaded to a file/string.
Two simple functions:
private async Task TryLoadCookiesAsync()
{
if (!File.Exists(_cookieFile))
return;
try
{
using var fs = File.OpenRead(_cookieFile);
var currentCookies = JsonSerializer.Deserialize<CookieParam[]>(fs);
await _page.SetCookieAsync(currentCookies);
}
catch (Exception ex)
{
_log.Warning(ex, "Exception loading cookies.");
}
}
private async Task TrySaveCookiesAsync()
{
try
{
// Attempt to get cookies from browser:
var cookies = await _page.GetCookiesAsync();
using var fs = File.Create(_cookieFile);
await JsonSerializer.SerializeAsync(fs, cookies);
}
catch (Exception ex)
{
_log.Warning(ex, "Exception saving cookies");
}
}
Expected behavior:
TryLoadCookiesAsync() to be able to be loaded.
Actual behavior:
Throws an exception "The node must be of type 'JsonObject'".
Versions
Which version of PuppeteerSharp are you using? 20.0.0.5
Which .NET runtime and version are you targeting? .NET 8
The text was updated successfully, but these errors were encountered:
Description
The current
CookiePartitionKeyConverter
doesn't currently support deserialization if the key is already a string. Essentially, trying to serialize these back out to a file, and then read back in again doesn't currently work, because the current writer writes as a string, and the reader will attempt to read an object. This currently works in puppeteer, because it's expecting an object from CDP, but it should still be able to deserialize if the cookies are offloaded to a file/string.Two simple functions:
Expected behavior:
TryLoadCookiesAsync() to be able to be loaded.
Actual behavior:
Throws an exception "The node must be of type 'JsonObject'".
Versions
The text was updated successfully, but these errors were encountered: