Overview:
This is a heads up for changes coming in Chrome 79 relating to the Tab type returned via API calls like chrome.tabs.update and chrome.tabs.create. The Tab.url property now contains the last committed URL of the main frame of the tab. There is also a new property, Tab.pendingUrl, which contains the URL that the tab is navigating to if there is currently a pending navigation (and isn’t present if there is not). These concepts are explained further below, along with potential changes you may need to make.
Background on Pending / Committed URLs:
Understanding pending and committed URLs requires some understanding of navigations in browsers.
When a navigation is initiated (link clicked, chrome.tabs.update called, etc.) the resource is requested. At this point the URL is considered to be ‘pending.’ The tab still shows the page content from the last committed URL, which is still the current security context for the tab. When a response is received, the browser commits the navigation. The ‘pending URL’ becomes the ‘last committed URL,’ the content of the tab starts updating, and the security context for the tab switches to the new page. Note that some navigations, such as those that turn out to be downloads, may never commit.
Previously, the ‘Tab.url’ property corresponded to the visible URL in the omnibox, which followed more complex and context-specific rules. For navigations started within a web page, the visible URL remained the last committed URL, but for navigations started in the address bar or (at the time) via extension APIs, the visible URL was the pending URL. As of Chrome 79, ‘Tab.url’ is always the last committed URL (i.e., the page the tab is showing and the current security context) and ‘Tab.pendingUrl’ is present if and only if there is an ongoing navigation which has yet to commit.
Recommended Developer Actions:
Your extension may need changes if it was treating the ‘url’ property on a Tab object as ‘the URL that is being navigated to’ rather than 'the URL of the current page.' This would have been unreliable before, and these changes may help uncover race conditions that existed in the extension. You can verify whether your extension has been affected by testing on Chrome 79 (currently on Canary and Dev).
The main cases that will likely need changes (and the recommended fixes) are:
If your extension calls a method like chrome.tabs.update or chrome.tabs.create and expects the ‘url’ property from the callback to match the newly requested URL, it should likely use ‘pendingUrl’ now. (When this callback comes back, the navigation has only just been initiated, meaning the URL being navigated to will be in ‘pendingUrl’ rather than ‘url.’)
If your extension is trying to retrieve the ‘url’ for a tab which may be mid-navigation (such as if you happened to call chrome.tabs.get or chrome.tabs.query right after a navigation was initiated), then you might have a race condition which this change exposes. That is, the navigation may or may not have committed by the time the callback is called. For more reliable behavior, we recommend waiting to call APIs like get or query until after the navigation has committed.
An example illustrating both these cases with the values ‘url’ and ‘pendingUrl’ take is shown below:
function waitForTabLoad(loadingTabId) {
return new Promise(function(resolve) {
chrome.tabs.onUpdated.addListener(function _listener(tabId, info, tab) {
if (loadingTabId == tabId && tab.status == 'complete') {
chrome.tabs.onUpdated.removeListener(_listener);
resolve();
}
});
});
}
chrome.tabs.create({url:'https://chrome.google.com/'}, function(tab) {
console.log('Tab pending URL: ' + tab.pendingUrl);
// Tab pending URL: https://chrome.google.com/
console.log('Tab URL: ' + tab.url);
// Tab URL:
waitForTabLoad(tab.id).then(function() {
chrome.tabs.get(tab.id, function(loadedTab) {
console.log('Tab pending URL: ' + loadedTab.pendingUrl);
// Tab pending URL: undefined
console.log('Tab URL: ' + loadedTab.url);
// Tab URL: https://www.google.com/chrome/
console.log('Tab title: ' + loadedTab.title);
// Tab title: Google Chrome
});
});
});Since this change only affects the behavior of Tab objects during the time between a navigation being initiated and it committing, we expect that most extensions will not be affected. We apologize for any inconvenience these changes cause, but ultimately they give extensions a more accurate view of the state of the tab. Extensions that care what page the tab was showing will work better than before (since they won't incorrectly see pending URLs), while extensions that care what pending navigation was happening now have a more explicit way to get that URL.
--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/2f2df700-0f13-474e-a777-45cee6625846n%40chromium.org.