Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make multiple parallel web html requests in a Chrome Extension?
    text
    copied!<p>I'd like to retrieve and parse multiple html pages within a Chrome extension. </p> <p>Using Web Workers for each request seemed like a simple way to make them execute in parallel. Is that possible? My attempt failed, perhaps because it's a known <a href="http://code.google.com/p/chromium/issues/detail?id=45382" rel="nofollow noreferrer">permissions bug</a>. </p> <p>As a workaround, I guess I could have the main extension page do multiple asynchronous XmlHttpRequests, then have the callback send the result page to Web Workers for parallel parsing. But that method raises the question of how many asynchronous parallel requests can Chrome make at once? That question has been asked <a href="https://stackoverflow.com/questions/561046">here</a>, without answer. </p> <p>The Chrome Extension I'm writing is a Browser Action.</p> <p>Code for the worker:</p> <pre><code> // Triggered by postMessage in the page onmessage = function (evt) { var message = evt.data; postMessage(message.count + " started"); update(message.count, message.url); }; // parse the results page function parseResponse(count, url, resp) { var msg = count.toString() + " received response "; postMessage(msg); } // read the Buganizer URL and parse the result page var update = function(count, url) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { parseResponse(count, url, xhr.responseText); } } xhr.onerror = function(error) { var msg = "!>: " + count + ": error "; postMessage(msg); } var url = "http://www.hotgrog.com"; // for testing (manifest has permissions for this url) xhr.open("GET", url, true); xhr.send(); postMessage(url); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload