I want to get the previous URL of a tab.
So if the back button it not greyed out, and you press it, the URL that then appears in the URL bar is the one I want.
Q: Why don’t you use tabs.goBack() ?
A: Because I only want to know the previous URL.
I do not want to change the tab’s URL.
Q: Why do you need this?
A: If a download’s referrer is null, I want to automatically determine a suitable referrer.
In some cases, the current tab’s previous URL is exactly what I want.
Someone has suggested using webNavigation.onCommitted:
I’m using browser.tabs.onRemoved and browser.tabs.onUpdated instead.
Because my extension already has the “tabs” permission, and if I wanted to use webNavigation.onCommitted, I’d have to add another permission.
The attached test extension demonstrates this.
But maybe there’s a better way to do this.
Is there an API where I can get a tab’s previous URL?
I’ve looked at the “history” API, but it doesn’t seem to offer this.
history.zip (4.2 KB)