chrome headless not support get browser cookie

1 Answer 24 Views
Chrome
Jun
Top achievements
Rank 1
Iron
Jun asked on 23 Apr 2024, 03:32 AM

I use ActiveBrowser.Cookies.GetCookies(BaseUri); to get browser cookie, cookie is got, but all expired cookie. The same code if I set chrome not headless, which could get un-expired cookie. Is it not supported yet?

Chrome headless:

Chrome:

Elena
Telerik team
commented on 25 Apr 2024, 02:00 PM

Hi Jun, 

As far as I understand you are running the tests in Chrome in its mode using extension. Please, change the test settings so that the test runs in Chrome without the extension. Then let me know if getting the cookies sets these with expired dates again. 

If so, please, prepare a sample test/code to share which runs against a public accessible page - this will allow me to reproduce the misbehavior and continue working on it.

Regards,
Elena

Jun
Top achievements
Rank 1
Iron
commented on 10 May 2024, 03:12 AM

Hi Elena, 

Thanks for update. I tried again, still the same issue~_~

settings.Web.DefaultBrowser = BrowserType.ChromeHeadless;
settings.Web.UseBrowserExtension = false; 

var url = "https://www.telerik.com/forums/chrome-headless-not-support-get-browser-cookie";
ActiveBrowser.ClearCache(BrowserCacheType.Cookies);
ActiveBrowser.NavigateTo(url);
var cookies = ActiveBrowser.Cookies.GetCookies(url);

 

for chrome:

for chromeheadless:

 

1 Answer, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 14 May 2024, 01:22 PM

Hello Jun,

Thank you for sharing an example of the issue you experienced - this helped me a lot. 

So, it turns out that getting the cookies is too soon after the navigate action and this is the reason why the cookie object remains empty. To fix this insert a short delay after the NavigateTo() method: 

System.Threading.Thread.Sleep(5000);

All in all the snipped should look like this:

var url = "https://www.telerik.com/forums/chrome-headless-not-support-get-browser-cookie";
ActiveBrowser.ClearCache(BrowserCacheType.Cookies);
ActiveBrowser.NavigateTo(url);
System.Threading.Thread.Sleep(5000);
var cookies = ActiveBrowser.Cookies.GetCookies(url);

I hope this helps!

Regards,
Elena
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Chrome
Asked by
Jun
Top achievements
Rank 1
Iron
Answers by
Elena
Telerik team
Share this question
or