2

Suppose I am using WinInet/WinHTTP for crawling a website. In the past I could simply ask a user to login to a website using either embedded IE control or the IE browser and WinInet would use the same cookies as the IE browser. Now that will not anymore as the Internet Explorer is getting old and removed very soon.

For whatever reason Edge browser does not wrap/use the Windows Internet settings / cookies storage... Does anyone have experience login through an embedded webview2 ... fetch cookes and transfer to WinInet? For purpose being here that you can use WinInet/WinHTTP to crawl the website in login'ed state.

Is it a feasible solution login through embedded WebView2 control and transfer all cookies to WinInet before issuing WinInet HTTP requests?

(I have added a Delphi specific tag (TEdgeBrowser) but I am intersted in hearing if the above described concept in general can be brought to work.)

Tom
  • 3,587
  • 9
  • 69
  • 124
  • 3
    We added a [CoreWebView2.CookieManager](https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.cookiemanager) to WebView2 so you should be able to enumerate all cookies in WebView2 and set them on to wininet or vice versa. WebView2 and Edge is based on chromium and has its own HTTP stack and state location so is not connected to wininet. – David Risney Jul 30 '21 at 21:25
  • 1
    @DavidRisney Your helpful comment should be an answer. – O. Jones Jul 31 '21 at 14:01
  • @DavidRisney Thank you. I think many (anyone using Windows API for crawler) could use that as an answer. If anyone has extended answers do feel free to make. It is really a must for many I think to be able takeover login related cookies and make requests in with the same credentials. Having a documented/accepted/recommended/supported method of doing this is a huge help. – Tom Jul 31 '21 at 22:26
  • 1
    I wasn't going to add it because my answer doesn't say how to actually use CookieManager to interact with Wininet, but if you say this is good enough then I'll do it =) – David Risney Aug 02 '21 at 16:20
  • @DavidRisney I have upvoted for now. But it one answer at least :) One extra question... It is not like I can enumerate/copy all cookies in general Windows Edge browser... Only those cookies set in my "own" embedded webview2 in my own application, correct? But that is either way also sufficient to solve my problems. (With IE, one can even open it as an external browser. And whatever login the user, my WinInet code automatically gains access to.) – Tom Aug 03 '21 at 18:34
  • 1
    Correct just your cookies. More specifically, when you create the WebView2 you can specify (or you get a default folder relative to your exe) the user data folder to use. This is the folder that stores all state including all cookies. The CookieManager interacts with all cookies in that user data folder. – David Risney Aug 03 '21 at 20:48
  • @Tom: I think, what you want would be a HUGE security problem. Suppose I install your app, then you want to login to ALL the sites, I have logged into in Edge and do things on my behalf, like checking my bank accounts? NO-NO! – Poul Bak Aug 04 '21 at 06:58

1 Answers1

2

We added a CoreWebView2.CookieManager to WebView2 so you should be able to enumerate all cookies in WebView2 and set them on to wininet or vice versa. WebView2 and Edge is based on chromium and has its own HTTP stack and state location so is not connected to wininet.

David Risney
  • 3,886
  • 15
  • 16