Frontend Development

Content script comunicating with html page

Submitted by A, , Thread ID: 22817

Thread Closed
A
User Icon
\(_o)/
Level:
0
Reputation:
206
Posts:
5.52K
Likes:
1.24K
Credits:
50.7K
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.

RE: Content script comunicating with html page

Burned Designs
Web Developer/Designer
Prime
Level:
0
Reputation:
5
Posts:
115
Likes:
9
Credits:
484
21-08-2016, 11:47 AM
#2
Okay my question is are you using this script in an html file if so why html why not just run the script with .js extension or why not use php to include the html file with <?php include 'background.html'; ?>
[Image: SIG.PNG]

RE: Content script comunicating with html page

A
User Icon
\(_o)/
Level:
0
Reputation:
206
Posts:
5.52K
Likes:
1.24K
Credits:
50.7K
OP
21-08-2016, 04:29 PM
#3
21-08-2016, 11:47 AM
BurnedDesigns Wrote:
Okay my question is are you using this script in an html file if so why html why not just run the script with .js extension or why not use php to include the html file with <?php include 'background.html'; ?>

Because the file needs special treat lol.
And keep in mind that this is for a chrome extension.

If i simply add it like that
Code:
<script src="/js/content.js"></script>

It won't work, i've read a few posts about this and found out what i wrote above.

I forgot to mention, that it has to have GM_xmlhttpRequest granted.

RE: Content script comunicating with html page

zica66
Newbie
Level:
0
Reputation:
0
Posts:
16
Likes:
3
Credits:
26
28-12-2017, 05:26 AM
#4
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:

i can handled for you by c# bro that easy

Users browsing this thread: 2 Guest(s)