Frontend Development

Content script comunicating with html page

Submitted by A, , Thread ID: 22817

Thread Closed
20-08-2016, 09:53 PM
This post was last modified: 20-08-2016, 09:54 PM by A
#1
I need my content script to run with privileges.

For my script to perform a privileged action, it needs to send a "message" to my background page,(background.html), so the background pages peforms it for it.

Here is my current content script:
Code:
function checkReq(){
var list = document.getElementById("gkpluginsExtListReq");
if(list===null){
return;
}
list.title = "ready";
if(list.childNodes.length>0){
var curReq = list.firstChild;
if(typeof curReq.innerHTML=="undefined"){
list.removeChild(curReq);
return;
}
var obj = JSON.parse(atob(curReq.innerHTML));
obj.onload = obj.onerror = obj.onabor = function(response){
var txtout = document.createElement("textarea");
txtout.id = obj.extreqid;
txtout.style.display = "none";
var Hfres = response.status+" "+response.statusText+"\r\n"+response.responseHeaders;
if(response.finalUrl){
Hfres += "FinalLocation: "+response.finalUrl+"\r\n";
}
if(obj.returndtaescape){
txtout.value = escape(Hfres+"\r\n"+response.responseText);
}else if(obj.returndtab64){
txtout.value = btoa(Hfres+"\r\n"+response.responseText);
}else{
txtout.value = Hfres+"\r\n"+response.responseText;
}
document.body.appendChild(txtout);
};
GM_xmlhttpRequest(obj);
list.removeChild(curReq);
}
}
setInterval(checkReq,100);

My background.html page is empty, because i until now, i had no luck to let it "comunicate" with my content script.
I appreciate any help.

P.S: My current project is a extension for google chrome, and the Message Passing page from google chrome developer section didn't really help me out.

Users browsing this thread: 4 Guest(s)