开发者

WebBrowser control, isolation and IE8 InPrivate mode

I have a need to run some automation tasks in a web browser contr开发者_如何学Gool 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!


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


Here's some code that will give you access to an InPrivate IE

Friend Function Open(Optional ByVal Url As String = "about:blank", Optional ByVal WindowState As ProcessWindowStyle = ProcessWindowStyle.Hidden) As WebBrowser
On Error Resume Next

Dim Start As New ProcessStartInfo
Dim Windows = New ShellWindowsClass
Dim Count = Windows.Count
Start.FileName = "iexplore.exe"
Start.Arguments = "-private -nomerge " & Url
If WindowState = ProcessWindowStyle.Hidden Then
  Start.WindowStyle = ProcessWindowStyle.Minimized
Else
  Start.WindowStyle = WindowState
End If
Process.Start(Start)

Wait.Reset()
Do
  If Windows.Count > Count Then Exit Do
Loop While Wait.Waiting

Browser = Windows(Count)
Browser.Visible = (WindowState <> ProcessWindowStyle.Hidden)
Return Browser
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜