Announcement: Upcoming change to make the url property on Tabs more reliable.

1,772 views
Skip to first unread message

Tim

unread,
Oct 11, 2019, 7:52:08 PM10/11/19
to Chromium Extensions

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.

Prokash Biswas

unread,
Feb 14, 2020, 4:38:07 AM2/14/20
to Chromium Extensions

Eduardo Sanz García

unread,
Nov 13, 2020, 9:47:22 AM11/13/20
to Chromium Extensions, tjud...@chromium.org
I was trying to identify the first fired event from 'onUpdate' (it is fired multiple times during the loading of a page). I was hoping to find  'pendingUrl'  defined only on the first callback, but it is always  undefined.

Is there another way to achieve this?

tjud...@chromium.org

unread,
Nov 13, 2020, 3:41:50 PM11/13/20
to Chromium Extensions, edu...@hypothes.is, tjud...@chromium.org
Yeah, onUpdated fires every time a property on the tab changes and that only happens after a navigation has committed and data starts loading in on it. 

Why are you needing to identify the first fired event? If you're wanting fine grained details about the loading of a page, perhaps the webNavigation API might be more what you're looking for?

Eduardo Sanz García

unread,
Nov 17, 2020, 5:50:31 AM11/17/20
to Chromium Extensions, tjud...@chromium.org, Eduardo Sanz García
I am trying to reset the badge text on the first fired event.

Simeon Vincent

unread,
Nov 20, 2020, 2:32:04 AM11/20/20
to Eduardo Sanz García, Chromium Extensions, tjud...@chromium.org
Hey Eduardo,

It doesn't sound like your issue is directly related to this announcement. As such, if you'd like to continue talking about your use case and possible approaches, I'd ask that you start another thread for discussion purposes.

Cheers,

Simeon - @dotproto
Chrome Extensions DevRel


--
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.
Reply all
Reply to author
Forward
0 new messages