Hi,
with our add-on, we want to determine page load times using WebExtensions API.
If a page is redirected we need to know the originally entered URL.
Let’s give an example:
- Load www.firefox.com (page is redirected to https://www.mozilla.org/en-US/firefox/new/?utm_medium=referral&utm_source=firefox-com).
- Assume the new Mozilla.org page needs 1 second to load
- Our add-on must create a record like “www.firefox.com;1000”
The “1000” at the end is the page load time in milliseconds.
To determine the original (not redirected URL) we add a listener to the onBeforeRequest event. Within the callback function, we determine the URL from the tab and not from the given parameter as the URL within the parameter is not always the same URL seen in the address bar.
We are using the following code snippet in the callback function to determine the URL (“details” is the parameter of the callback function):
var tabUrl;
browser.tabs.get (details.tabId, function (tab)
{
// Null or undefined
if (tab == null)
return;try { tabUrl = new URL (tab.url); } catch (e) {return;}
});
And here is the problem:
For the main frame the variable tabUrl contains the URL from the page you are coming from (and not the URL of the address bar).
Does anybody know how to get the originally entered (not redirected) URL (www.firefox.com in my example)?