I use XMLHttpRequest
in content script. The code works whenever a new tab opens, but it stops working whenever a tab is updated. tabupdation API only works in background.
Manifest:
{
"manifest_version": 2,
"name": "extension",
"version": "1.0",
"description": "",
"icons" : {
"48" : "48X48.png",
"128": "icon1.png"
},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"],
"all_frames": true
}]
}
The content script uses XMLHttpRequest
.
var string="string on web page ";
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","url/folderName/file.php?q=string",true,"userName","password");
xmlhttp.send();
string is actually the value which i retrieved from web page and send in xHR but when tab url changes previous values are displayed instead of new one. This code does not work whenever i open url in current tab e.g. as we do in youtube, open video suggested on side but if we open any video in new tab then content script work/if we reload that tab then content script worked.