1

I need to get cookies of particular website from puppeteer chrome session and add these cookies to script.Here is code I am doing to get cookies form page:

page.GetCookiesAsync();

But it return:

Id = 7315, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

Other way I have tried:

page.Client.SendAsync("Network.getAllCookies");

Both methods not working for me. What I am doing wrong?

Nekuskus
  • 143
  • 1
  • 11
Mobeen
  • 45
  • 1
  • 8

1 Answers1

2

The execution of the GetCookiesAsync task needs to be awaited, like this:

private async Task YourMethod()
{ 
    var result = await page.GetCookiesAsync();
}

You might need to change your callers for this.

Try to read about asynchronous programming in C#: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/


So what you are seeing with this:

Id = 7315, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

is the async task not yet completed. GetCookiesAsync returns immediately. If you want to want to wait for the result, you should await it.

Stefan
  • 17,448
  • 11
  • 60
  • 79
  • You mean like this page.Client.SendAsync("Network.getAllCookies").Wait(); – Mobeen Sep 26 '20 at 10:31
  • I have tried this code: page.Client.SendAsync("Network.getAllCookies").Wait(); var ob = page.Client.SendAsync("Network.getAllCookies"); – Mobeen Sep 26 '20 at 10:31
  • If you're doing it sync, you will need: `Result` – Stefan Sep 26 '20 at 10:37
  • @Mobeen: try to read up into async/await and Tasks in C# ... it will help you get forward with these things ;-) – Stefan Sep 26 '20 at 10:39
  • Can you remove the second example @Stefan? That could be problematic. – hardkoded Sep 26 '20 at 14:07
  • @hardkoded: sure, but it is the one that eventually helped OP. – Stefan Sep 26 '20 at 14:24
  • 1
    @Mobeen: the solution offered (with `.Result`) is not really recommended since it can lead to problems. For it to work properly, use the links I provided. I will remove the example. – Stefan Sep 26 '20 at 14:25