Inconsistent behaviour of the browser.tabs.onUpdated callback

By design Issue #10246170

Details

Author
Andrey M.
Created
Dec 16, 2016
Privacy
This issue is public.
Reports
Reported by 3 people

Sign in to watch or report this issue.

Steps to reproduce

onUpdated callback receives inconsistent params:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/onUpdated

Steps to reproduce

Create extension with this code:

function handleUpdated(tabId) {
  console.log("Updated tab: " + tabId);
}

function handleCreated(tab) {
  console.log("Created tab:" + tab.id);
}

browser.tabs.onCreated.addListener(handleCreated);
browser.tabs.onUpdated.addListener(handleUpdated);
  1. Open new tab
  2. Enter bing.com and press enter

Expected result

We should receive the same tabId for each call.

Actual result

// Tab is created
Created tab: 10
Updated tab: 10
Updated tab: 10
// Navigating to bing.com in the same tab, tabId has changed for no reason
Updated tab: 11

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Sebastian P.”

      Changed Assigned To from “Sebastian P.” to “Akshay P.”

      Changed Assigned To from “Akshay P.” to “Mohit R.”

      Changed Status to “Confirmed”

    • Same happened for me but with onBeforeRequest

      browser.webRequest.onBeforeRequest.addListener((event) => {
        console.log(event.tabId, event.url)
      }, {
        urls: [""],
        types: ["main_frame"]
      });
      

      then if I redirect to https://www.ebates.com/backcountry-com_10019-xfas?AutoLoginID=Yk5XnrwWV6cuYT%2FgZwdEaw%3D%3D&tb=yes&domainName=backcountry.com&sourceName=toolbar&toolbarFeatureId=TOPSTORES&toolbarId=284798516&eeid=26142 where it executes redirect in the same tab via location.href = 'http://...' I’m getting updated tabId;

    • Microsoft Edge Team

      Changed Assigned To to “Akshay P.”

      Changed Assigned To to “Akshay P.”

      Changed Assigned To from “Akshay P.” to “Scott L.”

      Changed Status from “Confirmed” to “By design”

    • Thanks for filing this bug! I investigated more and it turns out that this occurs due to what’s called a virtual tab switch. Edge will do this (for example) when switching between the new tab page/start page and internet pages, as well as when navigating across the internet/intranet boundary. A workaround is to add a tabs.onReplaced() listener which will fire when a virtual tab switch occurs. In the parameter to the callback will be the id of the tab that was removed as well as the new tab id that was generated. 

    You need to sign in to your Microsoft account to add a comment.

    Sign in