What I am trying to achieve here, is to execute a XHRHttpRequest()
on a worker to speedup my extension. I am using worker_proxy.js
from here. It is working totally fine except that I am unable figure out how to pass a string to this worker.
Here is my code:
manifest.json
{
"permissions": [
"alarms",
"activeTab",
"tabs",
"webNavigation",
"http://*/*",
"https://*/*",
"cookies"
],
"options_page": "options.html",
"background": {
"persistent": false,
"scripts": [ "worker_proxy.js","background.js"]
},
"content_scripts": [
{
"matches": ["https://*/*","http://*/*"],
"js": ["jquery-2.1.4.js","hmac-sha256.js","enc-base64-min.js","worker_proxy.js","content.js"]
}
],
"web_accessible_resources": [ "worker_proxy.html","worker.js"],
}
worker.js
var somestring=getStringFromContentJS()
var xhr=new XMLHttpRequest();
var request="GETgoogle.com"
xhr.open("GET", request, false);
xhr.send(someString);
postMessage('Result\n' + xhr.responseText);
content.js
var az_worker = new Worker(chrome.runtime.getURL('getAzProducts.js'));
az_worker.onmessage = function(event) {
alert('Message from worker: ' + event.data);
};
I am able to receive the data from worker.js
, but how do I send data to it .i.e.,
var somestring=getStringFromContentJS()