Can Web Workers be used to filter HTML nodes from a list?

360 views Asked by At

I'm trying to do a script that may requiere a heavy filtering of html tags. I thought I could take the chance to learn about web workers but, this may not be the right use for them.

I wanted get every image on a page and filter by size. I know I can't pass an object to the worker and I think they can't have access to the DOM, so I did this:

window.addEventListener("load", init);

function init () {
    console.log("init");
    var imgs = document.querySelectorAll("img");
    var worker = new Worker("worker.js");
    console.log(JSON.stringify(imgs));
    worker.postMessage(JSON.stringify(imgs));

    worker.addEventListener("message", read_message);
}

Unfortunatly, it doesn't look like I can transform a NodeList into an object... Do you think I should find another way of doing this or is it posible to send that information any other way?

0

There are 0 answers