I have a Chrome extension that checks to see if the page is NYTimes.com. If so, it stores the title of that page & sends it via PHP. The listener itself works. I can tell because the PHP side outputs a timestamp. For every request, the timestamp is present.
The problem is that when I open a Tab by holding CTRL, it is not the active tab. So a blank field is sent to my PHP file & I don't know the title of the page. How would I get the data from a page that is loaded, but is not the active window?
chrome.history.onVisited.addListener(function(result){
if (result.url.search("www.nytimes.com") >= 0 || result.url.search("nytimes.com") >= 0){
title = result.title;
$.post("http://myURL.com/tmp/test.php", {titletag: title});
console.log("Saving "+result.title);
}
});
There is a workaround to be able to do the same thing :
Declare the injection of a javascript file in your manifest :
"content_scripts": [{
"matches": ["http://www.nytimes.com/*", "https://www.nytimes.com/*"],
"js": ["my_script.js"],
"run_at": "document_start"
}],
Your my_script.js :
chrome.extension.sendRequest({'title':document.title});
In your extension main script :
chrome.extension.onRequest.addListener(function(data) {
$.post("http://myURL.com/tmp/test.php", {titletag: data.title});
}