2

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.

pca1987
  • 323
  • 3
  • 15
  • 1
    I've found out that this helps: `GeckoPreferences.User["browser.xul.error_pages.enabled"] = true;` After that, you can check for "IsErrorPage" in Navigated event. But seems like I can't replace that document content. So the problem persists. – pca1987 Dec 16 '13 at 13:25

1 Answers1

0

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.";
};
Tom
  • 6,325
  • 4
  • 31
  • 55
  • Thank you for your time. I've tried this and tried placing a breakpoint in every method in MyPromptService and seems like it's not working. Any ideas? (I've left all thorw notimplemented exception there and none were launched). I have disabled the error pages property and I have created the new instance of the class `PromptFactory.PromptServiceCreator = () => new MyPromptService();`. PS: to reproduce the error I'm trying to navigate to a non-existing ip, such as http://10.0.0.77. – pca1987 Dec 16 '13 at 15:00
  • updated answer - (as PromptService isn't invoked for all errors.) – Tom Dec 16 '13 at 17:27