views:

621

answers:

3

I have a need to run some automation tasks in a web browser control but I seem to be facing a few limitations/unknowns that I'm not 100% sure how to resolve. The application I'm running is not for public release, so I can enforce a prerequisite that IE8 is installed.

GeckoFX (http://geckofx.org) would be great except it does not offer me an acceptable way to manipulate the DOM as I would using the WebBrowser's InvokeMember method on HtmlElement objects.

WebKit.net would be even better but it's too early in its development to offer the functionality I need to do this either.

This leaves me with the WebBrowser control. The problem with WebBrowser though is that it just runs IE, which is a big fat shared environment with all processes. In other words, all instances share cookies, sessions, proxy settings, etc.

Here's what I want:

  • At the end of an automation session, cookies/sessions/cache objects are not retained. Rather than clearing the global Temporary Internet Files folder, is there a way for me to access the InPrivate mode exposed by IE8?

  • If there is a way to access InPrivate browsing, is it possible for me to run two InPrivate-mode sessions side-by-side isolated from each other?

Ideally I'd like to be able to run multiple isolated automation tasks in separate threads, each with its own private browser control, each with its own isolated session/environment that is not retained when the task completes.

Any help or input into this would be appreciated!

A: 

Just guessing

In HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Safety\PrivacIE, set StartMode to 1 would turn on by default see if the setting can be customized via IDocHostUIHandler2::GetOverrideKeyPath

Update: hooking WinInet APIs could give the option for alternative session storage, however this is error-prone and may require patch when winInet is updated.

Sheng Jiang 蒋晟
A: 

No, you cannot run the WebBrowser control in InPrivate mode; it's simply not a supported scenario.

Yes, you can run two instances of IE in InPrivate mode and isolate them from each other.

Use the command line: iexplore.exe -private -nomerge

EricLaw -MSFT-
doh. ok, thanks.
Nathan Ridley
A: 

Hi Sheng,

Can you provide some sample code that uses the IDocHostUIHandler2::GetOverrideKeyPath workaround and makes an embedded WebBrowser control effectively go into InPrivate mode? I need to do something similar: isolate cookies for webbrowser control embeded in an exe so that cookies like "ASP.NET_SessionId" from two different instances of the exe don't step over each other. I'm open to using unsupported methods if that's what it takes.

Much appreciated, Manish.

Manish

related questions