0

I'm trying to do something so simple, yet it seems like there's no way to do it. Im making a chrome extension, I want the extension when its clicked on to take the full URL of the current page as well as the page before it, that's all. document.referrer doesn't work all the time, and if it works it doesn't return the full URL, it takes out the parameters. I need the full URL of the referrer page. Is there anyway to get that, maybe using chrome APIs?

  • https://stackoverflow.com/a/3528331/10781526 as Lance Pollard mentioned in the comment section, document.referer does not work that good. You could use a cookie to store the data. There is also a `onCommitted` event: https://stackoverflow.com/a/25241421/10781526 and https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation/onCommitted – Andreas Apr 12 '20 at 19:42
  • Is there a way to know how the current page was navigated to using this approach? example, "linked" vs "typed" – Saif Abuhashish Apr 12 '20 at 19:50
  • No I don't, sorry – Andreas Apr 12 '20 at 19:58
  • There is transition Type: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation/transitionType – Andreas Apr 12 '20 at 20:01
  • Thank you, but Im having a hard time understanding how this gets me the previous page, if he maps the id of the current page to the URL and then retrieves it, isn't that going to get me the URL of the page not the previous one? Am I missing something here? – Saif Abuhashish Apr 12 '20 at 22:11
  • There's no API to "get" the previous page, the are only events to observe navigation inside the background script like chrome.tabs.onUpdated or lots of chrome.webNavigation events. You'll use a global variable like urls={} and then update it like urls[tabId] = url – wOxxOm Apr 13 '20 at 04:11
  • I still dont understand how thats gonna get me the previous URL. I load a page, I save tabId and map it to my current URL, how can I use that information to get the previous URL if everytime I load a new thing in my tab my previous value in the map gets oveerwritten. – Saif Abuhashish Apr 25 '20 at 23:39

0 Answers0