Skip to content

Instantly share code, notes, and snippets.

@fzzzy
Created October 18, 2011 20:18
Show Gist options
  • Save fzzzy/1296589 to your computer and use it in GitHub Desktop.
Save fzzzy/1296589 to your computer and use it in GitHub Desktop.
use henri's parser from a webworker
importScripts('../dom.js');
importScripts('domstr.js');
// Mock up enough fake stuff so that the parser can load
// This can be removed once using the non-GWT compiled parser
window = {
location: {href: "foo"},
setTimeout: function() {
return Function.prototype.apply(setTimeout, arguments);
},
clearTimeout: function(arg) {
return Function.prototype.apply(clearTimeout, arguments);
}
}
document.location = window.location;
document.write = function() {}
importScripts('parser.js');
var event = document.createEvent('customevent');
event.initEvent('DOMContentLoaded', false, true);
document.dispatchEvent(event);
document.implementation.mozSetOutputMutationHandler(
document,
function(evt) {
postMessage(JSON.stringify(evt));
}
);
function GET(url) {
var req = new XMLHttpRequest();
req.open("GET", url, false); // in a thread, so blocking ok
req.send('');
window.parseHtmlDocument(req.responseText, document,
function() {
postMessage(JSON.stringify({done: true}));
},
null);
}
onmessage = function(message) {
var url = message.data.url.toString();
GET(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment