2

In my chrome extension, I wanted to get the user given URL of the new chrome tab. The targeted page is a SAML based authentication page, which redirects and end up at idp page.

I started with simple approaches like: document.referrer which has given last referer, but not the initial url , which user entered in the URL bar.

2nd Approach:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
 console.log(changeInfo.url);
});

But for any TabStatus it doen't return the exact url which I expected.

Example:

console output:

chrome://newtab/
https://www.google.com/intl/si/gmail/about/#

2nd url is the landed page's URL but not the url I entered.

My next plan is to try chrome.webRequest.onBeforeRequest which seems complex, but before that, I wanted to know whether is there any easy way to get this?

Tharaka Deshan
  • 1,349
  • 3
  • 15
  • 30
  • If the URL in the address bar changes then chrome.tabs.onUpdated is the correct solution but you may be looking at the wrong console ([How to see background.js console?](/a/10258029)) or there's something else at play for which your question doesn't contain a reproducible [MCVE](/help/mcve). – wOxxOm Apr 23 '20 at 15:15
  • @wOxxOm , thanks! But I tried on the background console. chrome.tabs.onUpdated is not supported in default console. – Tharaka Deshan Apr 23 '20 at 18:50
  • 1
    Try reading `tab.pendingUrl`. – wOxxOm Apr 24 '20 at 04:02

0 Answers0