-1

I wanted to delete the cache and cookies of a C# web browser..

I uses the following code in formload method, but it is not working

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString());}}}})())");
}

please tell me how to fix this issue.

about code is not working.

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98

1 Answers1

0

The WebBrowser control is like an Interface of IE. If you want to clear Cache/Cookies in a meaningful way then you'll have to call the IE APIs for that. Otherwise you could use another User Control like Selenium which could give better results.

You can also refer to: https://social.msdn.microsoft.com/Forums/windows/en-US/71a5b2bb-f254-45b3-94a0-d194e335211c/how-to-clear-webbrowser-control-cookie-in-c?forum=winforms

and as @pmcilreavy suggested: How to delete Cookies from windows.form?

Selenium:

https://github.com/SeleniumHQ/selenium

shawkyz1
  • 886
  • 5
  • 19