Chrome extension API: tab id changes when using autocomplete
Reported by
markus.k...@gmail.com,
Apr 4 2017
|
||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 Steps to reproduce the problem: 1. Visit https://en.wikipedia.org to make sure the site is cached and in history 2. Install extension manifest.json: { "name": "Tab ID", "version": "0.1", "description": "Inconsistent tab id", "permissions": ["tabs"], "background": { "scripts": ["background.js"] }, "browser_action": { }, "manifest_version": 2 } background.js: chrome.tabs.onActivated.addListener( function(activeInfo) { chrome.extension.getBackgroundPage().console.log("Activated tab "+activeInfo.tabId); } ); chrome.tabs.onCreated.addListener( function(tab) { chrome.extension.getBackgroundPage().console.log("Created tab " + tab.id); } ); chrome.tabs.onUpdated.addListener( function(tabId, changeInfo, tab) { chrome.extension.getBackgroundPage().console.log("Updated tab " +tab.id); } ); chrome.tabs.onRemoved.addListener( function(tabId, removeInfo) { chrome.extension.getBackgroundPage().console.log("Closed " + tabId); } ); 3. Create a new tab and watch the tab id output by the extension 4. Go to https://en.wikipedia.org by selecting the URL using autocomplete 5. Close tab What is the expected behavior? In step 4: call of onUpdate with same tab id as in step 3 In step 5: call of onRemoved with same tab id as in step 3 What went wrong? In step 4: call of onActivated with a new tab id ("tab id as in step 3" + 2) In step 5: call of onRemoved with the new tab id new tab id ("tab id as in step 3" + 2) Did this work before? N/A Chrome version: 57.0.2987.98 Channel: n/a OS Version: 6.1 (Windows 7, Windows Server 2008 R2) Flash Version: Yes! Accessing the tab id is extremely inconsistent. Four similar callbacks as shown in the sample extension, and three different ways to get the tab id: tab.id, tabId, activeInfo.tabId.
,
Apr 4 2017
This is how prerender works. A hidden tab with tab id -1 is used to start rendering the search results. When it's ready it gets a new tab id and this new tab replaces the active tab in-place. You can use chrome.tabs.onReplaced event to catch the moment the actual tab is shown to the user. See the documentation: https://developer.chrome.com/extensions/tabs#event-onReplaced
,
Apr 4 2017
Thank you, chrome.tabs.onReplaced works for me, but I still do not get the chrome.tabs.onUpdate event where I can access the changed URL.
,
Apr 4 2017
>but I still do not get the chrome.tabs.onUpdate event where I can access the changed URL.
chrome.tabs.onUpdated isn't triggered for prerendered tabs because they're not real tabs yet, and don't have a real tab id.
If you want to monitor the url being loaded in such a hidden tab, use chrome.webRequest API events, for example:
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (details.tabId == -1) {
console.log(details.url);
}
}, {
urls: ["<all_urls>"],
types: ["main_frame"],
});
,
Apr 4 2017
Alternatively, you can get the tab details with an URL in chrome.tabs.onReplaced event listener by invoking chrome.tabs.get for the new replaced tab id.
,
Apr 5 2017
Thank you woxxom@ for diving into this! I am going to mark as wontfix. If you notice anything that still is not working please file a new bug. Thanks!
,
Apr 6 2017
The following revision refers to this bug: https://chrome-internal.googlesource.com/chrome-golo/chrome-golo/+/fdcfc730a5fc8c7d3de869146a09a2e367a4f4ca commit fdcfc730a5fc8c7d3de869146a09a2e367a4f4ca Author: Peter Schmidt <pschmidt@google.com> Date: Thu Apr 06 18:42:14 2017 |
||
►
Sign in to add a comment |
||
Comment 1 by ranjitkan@chromium.org
, Apr 4 2017