WebBrowser Management: Navigation Failure Detection

I host a web browser control that typically downloads external documents and then makes some changes using the HTML DOM.

We also embed user application links using a fake protocol such as "Close This", which are caught and processed in BeforeNavigate2 .

When a tarket link has a spelling error (for example, "spp: CloseWindow"), BeforeNavigate will not trigger custom processing. The browser control does not show a navigaiton error, but remains in READYSTATE_INTERACTIVE and does not launch NavigateComplete or DocumentComplete .


My problem: Most operations (like getting or updating content) are delayed and expect readistate to reach READYSTATE_COMPLETE . After clicking such an invalid link, the browser no longer updates - a state that I would like to avoid. How can i do this?

  • Can I find in "DownloadComplete" that the navigation is crashing? (Thus, I could ease the test to "READYSTATE_COMPLETE or READYSTATE_INTERACTIVE and last downloadComplete was broken ")
  • Can I "reset" control the browser READYSTATE_COMPLETE (maybe not)
  • Can I detect pseudo-protograms actually supported by the browser?

(In retrospect, the prefix xxxx: not such a good idea, but changing this now is a bit of a problem.)

+2
c ++ webbrowser-control
source share
2 answers

Internet Explorer and Windows have an extensible list of available protocols implemented in UrlMon.dll, I suppose. See here a little about IE architecture .

The reason you cannot detect a bad protocol in BeforeNavigate is because the protocol is unknown, so no real navigation happens. The browser decides to display the error page. Navigating on an error page does not seem to trigger all normal events.

However, there is a way to detect when navigation has passed in the weeds. If you connect to the DocumentCompleted event of a web browser, you can scan specific URLs for errors or, more generally, for URLs starting with res: //ieframe.dll.

Examples:

  • Res: //ieframe.dll/unknownprotocol.htm#spp: CloseWindow
  • res: //ieframe.dll/dnserrordiagoff_webOC.htm# http: // 192 ...

A cleaner way is to connect NavigateError to the DWebBrowserEvents2 interface .

+5
source share

We had a problem when placing a web browser control (Google Map) in that we would be notified when the navigation ( NavigateComplete ) was complete, but the web page itself did not finish rendering. To fix this problem, we added the javascript notifyInitialised function, which simply went to "app: // onInitialised" - a similar mechanism that you use.

Perhaps you could be something like this (if you have control over the pages the user is navigating to). You can add this notification mechanism and check it in your code. If it was not received after the specified timeout, you can assume that something went wrong and display the corresponding message.

If you're interested, we also used a mechanism to directly call javascript functions from our C ++ code, described here and here .

0
source share

All Articles