Extension Developers – Better Background XMLHttpRequests

XMLHttpRequests (XHR) are used for lots of things these days. When running a background XHR, however, you might experience some common issues like authentication or bad SSL certificate dialogs popping up. Another problem was starting an XHR, then closing the window – the XHR is closed. To help get around these inconveniences, Manish Singh (of Flock) adding support for a background mode (bug 383430). The details:

  • Do not attach to a window’s load group, so requests aren’t cancelled if the window closes (often the window isn’t really associated with the request anyway)
  • Do not get an nsIAuthPrompt by default, since we don’t want authentication dialogs to pop up randomly.
  • Provide an nsIBadCertListener implementation, again to prevent bad certificate dialogs to pop up randomly.
var req = new XMLHttpRequest();
req.mozBackgroundRequest = true;
req.open("GET", someURI);

The magic is handled by mozBackgroundRequest and it’s only available to chrome, not for web content.

3 thoughts on “Extension Developers – Better Background XMLHttpRequests

  1. Fantastic! Recently I encountered this problem and don’t know how to do with the certification’s popup.
    Thanks Mark!

  2. I agree with Jesse – I can think of a situation where I’d like the request to proceed if the window is closed, but still need authentication dialogs to pop up if required. I guess this is hard if authentication dialogs are attached to windows…

Comments are closed.