How to Intercept GeckoFx connection error

2.2k views Asked by At

Is there a way to intercept connection problems on client-side?

I mean if user loses connection and try to access a website, GeckoFx/Xulrunner shows a message "[url] could not be found. Please check the name and try again." on a alert-style message box.

Is it possible to change that message or intercept it to treat it and show an error page, for instance?

Found out the solution: After more testing and asking for help in geckofx, I saw that this line was missing:

GeckoWebBrowser.UseCustomPrompt();

And both this line and delegate assignment to PromptServiceCreator must be set BEFORE Xpcom.Initialize method. That was the part that took me so long to find out, since my Initialize method was in another class.

1

There are 1 answers

2
Tom On

If you set "browser.xul.error_pages.enabled" disabled (false) you can write your own PromptService.

First implement your own Prompt Service:

class MyPromptService : nsIPromptService2, nsIPrompt { .... }

Then early on in your program startup:

PromptFactory.PromptServiceCreator = () => new MyPromptService();

This will all you to do what you want with all alerts.

If that doesn't work then, your can always just modify the documents contents:

    browser.DocumentCompleted += (s, e) => 
{
  if (!sometest)
       return;

  GeckoHtmlElement g = (GeckoHtmlElement)browser.Document.DocumentElement;
  g.InnerHtml = "what ever you want.";
};