title: Parsing HTML DOM in web worker
body: <p>I am trying to extract content from web pages using my firefox/chrome/safari extension. Capturing works fine but when I capture full web pages, it takes a long time and UI gets blocked. I want to move the capture/DOM parsing code to a different thread (Web Worker). But web workers do not have access to the DOM. Is there a way I can work around this?</p>
  
  <p>I am using the following code to inject the script into the web page:</p>
  
  <pre><code>function executeScript(script, messageKey, callback) {
          var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
          var mainWindow = wm.getMostRecentWindow("navigator:browser");
          mainWindow.gBrowser.selectedBrowser.messageManager.loadFrameScript(script, true);
          mainWindow.gBrowser.selectedBrowser.messageManager.addMessageListener(messageKey, callback);
      }
  
  executeScript("chrome://extension/content/contentscript.js", "onSelectionReceived", onSelection);
  </code></pre>
  
  <p>All the DOM processing is happening inside this script 'contentscript.js'</p>