Breaking change in chrome.tabs.query extension API
Reported by
goservis...@gmail.com,
Mar 4 2016
|
|||
Issue description
Chrome Version : 49.0.2623.75
URLs (if applicable) : Extension background page
OS version : OSX 10.11.3
What steps will reproduce the problem?
In an extension background page, calling chrome.tabs.query({ url: chrome.extension.getURL('') + '*' }) returns an array of all open tabs.
What is the expected result?
Up to Chrome 48, the above method would return either the extension tab as an array containing a single item, or an empty array.
Example code:
chrome.browserAction.onClicked.addListener(function (tab) {
var extensionUrl = chrome.extension.getURL('');
if (tab.url.indexOf(extensionUrl) !== 0) {
// find extension tab or open new
chrome.tabs.query({ url: extensionUrl + '*' }, function (tabs) {
// Before Chrome 49, `tabs` would either be an empty array if the extension
// has no open tabs, or an array with one or more tabs containing extension pages.
// In Chrome 49, `tabs` is now an array containing all open tabs.
});
}
});
,
Mar 5 2016
My extension also has this problem in Version 49.0.2623.75 m. Calls to chrome.tabs.query with {url:'my url'} returns a list of Tabs even when the url does not match. Before, the list would be empty.
Simply running this in the console of an extension returns two Tabs instead of none!
chrome.tabs.query({active: true, title:'missing title'}, function(a){console.log(a)});
,
Mar 5 2016
This code used to work fine, since only a tab matching the supplied URL would be returned, or none at all. Now, multiple tabs are being returned.
var url = chrome.extension.getURL('my_popup.html');
chrome.tabs.query({ url: url }, function (foundTabs) {
if (foundTabs[0]) {
chrome.tabs.update(foundTabs[0].id, {
active: true
});
} else {
chrome.tabs.create({ url: url });
}
});
,
Mar 5 2016
My report is for a Windows desktop.
,
Mar 5 2016
As a workaround, I am trying to examine all the Tabs returned, and find my Tab... but there doesn't seem to be any useful information in the Tab object to help identify it. (I don't have "tabs" permission in the extension's manifest, because I don't need it to find and update my tab.)
,
Mar 8 2016
Same as everyone else, I need it to avoid creating duplicate tabs of the same page. Neither do I have `tabs` permission to further check URLs on all the tabs, since that requires new permission from the user.
,
Mar 8 2016
My workaround now is to remember the tab id when I make a tab (stored in localStorage) and attempt to reopen (chrome.tabs.update(id, {active:true}), fn) that tab later. If nothing is given to the fn, my tab must not be there, and I make a new one.
,
Mar 8 2016
I think that will fail (will focus to irrelevant tab) if user uses that same tab to navigate to another site.
,
Mar 8 2016
Good point about the tab being used to navigate to another site! Just tried it, and it doesn't work that way, fortunately. If the tab is used for a different URL, it must get a new id or something. Before navigating, my code would refocus on that tab. After navigating, my code would create a new tab.
,
Mar 9 2016
In any case, we're all referring to a breaking change in the API. If this is expected, we need a viable work around to identify a tab by its URL in order to avoid creating multiple tabs with the same URL.
,
Mar 9 2016
Thank you for providing more feedback. Assigning to requester "ellyjones@chromium.org" for another review. For more details visit https://sites.google.com/a/chromium.org/dev/issue-tracking/autotriage - Your friendly Sheriffbot
,
Mar 15 2016
,
Mar 29 2016
Is this going to be fixed? My extensions are suffering from this regression too and I don't want to ask for the "tabs" permission, since I don't really need it. Please consider a quick fix.
,
Mar 29 2016
Ah forgot to say that this bug is still there on 49.0.2623.110 ( 64-bit official build )
,
Apr 21 2016
For anyone who's coming here, should know that this issue has been fixed with the latest 50.0.2661.75 (Official Build) m (a 64 bit) @Google: would be nice if sometimes you answer to our issues...or at least update them with the current resolution status.
,
Apr 29 2016
Sorry for the late response, glad that the issue is fixed. Please feel free to reopen if needed. |
|||
►
Sign in to add a comment |
|||
Comment 1 by ellyjo...@chromium.org
, Mar 4 2016Hm. Is the result of chrome.extension.getURL('') + '*' a valid URL match pattern for chrome.tabs.query()? The only allowed schemes for URL match patterns are 'http', 'https', 'file', and 'ftp', according to https://developer.chrome.com/extensions/match_patterns - perhaps that generated pattern has a disallowed scheme (like 'chrome-extension') and so it's being ignored? Reporter: 1) Does the URL you're passing to chrome.tabs.query() start with one of the allowed schemes for URL match patterns?