Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load URL and getCookies Command result #1

Open
XavierLluch opened this issue Nov 4, 2015 · 3 comments
Open

How to load URL and getCookies Command result #1

XavierLluch opened this issue Nov 4, 2015 · 3 comments

Comments

@XavierLluch
Copy link

Hi!

I was trying, unsuccessfully, to load an url and check the cookies loaded:

chromeSession.SendAsync(new NavigateCommand
{
      Url = "http://www.google.com/"
});

ICommandResponse result =chromeSession.SendAsync(new GetCookiesCommand
{

}).Result;

Please could you explain briefly how to send command properly and how to recover results?

Thanks in advance for your effort and share your work!!!

@brewdente
Copy link
Member

Hey, I've been having problems with Chrome using the "remote-debugging-port" on the command line. I still haven't found out what or why. However, in order to get the result of the command (for instance, in your GetCookiesCommand case) you would use

var cookiesResponse = chromeSession.SendAsync(new GetCookiesCommand()).Result as CommandResponse<GetCookiesCommandResponse>;
if(null != cookiesResponse.Result)
{
   foreach(var cookie in cookiesResponse.Result.Cookies)
   {
      Console.WriteLine(cookie.Name);
   }
}

I hope you're actually able to navigate to a page. If I fire open chrome.exe --remote-debugging-port=9222 I can't do anything in that instance of the browser. It's very strange. As a result, I'm unable to test that the code above works. I'll still be doing some chrome.exe debugging, but I wanted to make sure I at least showed you how it's supposed to work when Chrome cooperates.

@XavierLluch
Copy link
Author

Hey Kevin, I've tested your code but, unfortunately, it doesn't work. I can load a page in Chrome and send a command to request cookies but CommandResponse is allways null. I use the code that your advise me:

chromeSession.SendAsync(new NavigateCommand
{
    Url = "http://www.google.com/"
}).Wait();

var cookiesResponse = chromeSession.SendAsync(new GetCookiesCommand()).Result as CommandResponse<GetCookiesCommandResponse>;
if (null != cookiesResponse.Result)
{
      foreach (var cookie in cookiesResponse.Result.Cookies)
      {
           Console.WriteLine(cookie.Name);
      }
}

Despite the solution you explain to me doesn't work I want to thank you to share your code and spend your time answering my dubts. I hope that you will succeed in this project!!!

@infiniteloopltd
Copy link

@XavierLluch

I fixed this code by making a change to the class MasterDevs.ChromeDevTools.Protocol.Chrome.Network.CookieSameSite
to add the value "None" to the enum.

namespace MasterDevs.ChromeDevTools.Protocol.Chrome.Network{
	/// <summary>
	/// Represents the cookie's 'SameSite' status: https://tools.ietf.org/html/draft-west-first-party-cookies
	/// </summary>
	[JsonConverter(typeof(StringEnumConverter))]
	public enum CookieSameSite
	{
		        None, //  fix
			Strict,
			Lax,
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants