From my chrome extension, I am trying to get the referrer link when a user navigates to Amazon.com from another website but I am running into some issues.
I am using accessing the current html page from chrome extension html-page-from-chrome-extension?noredirect=1&lq=1 and Accessing Current Tab DOM Object from "popup.html"? from-popup-html but still have issues.
My js in confirmation.js:
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'loading') {
console.log(tab);
console.log(document);
//console.log(document.referrer);
}
});
Currently, when this outputs the DOM of popup.html; not the current DOM of the tab the user is on. How do I get the document of the current tab the user is on?
Console.log(tab) provides the information for the current tab the user is on but I do not see any referrer attribute here.
Any advice on how I should solve this?
My manifest.json:
"permissions": [
"activeTab",
"tabs",
"storage",
"notifications"
],
"content_scripts": [
{
"matches": ["https://www.amazon.com/*"],
"js": ["confirmation.js"]
}
]
To check the Referer in action go to Inspect Element -> Network check the request header for Referer like below. Referer header is highlighted. Supported Browsers: The browsers are compatible with HTTP header Referer are listed below: Google Chrome.
$_SERVER['HTTP_REFERER'] will give you the referrer page's URL if there exists any. If users use a bookmark or directly visit your site by manually typing in the URL, http_referer will be empty. Also if the users are posting to your page programatically (CURL) then they're not obliged to set the http_referer as well.
Try this...
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.state === 'complete'){
chrome.tabs.executeScript(tabId, {
code: "document.referrer;"
},
function(result) {
// Here, you'll get the referrer
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With