Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting an error "Tabs cannot be edited right now (user may be dragging a tab)" on tab update/activate/focus event in chrome 91

After the recent Chrome update my extension started to fire "Unchecked runtime.lastError: Tabs cannot be edited right now (user may be dragging a tab)" when I attempt to use chrome.tabs API. There is not much info on this issue yet, but I believe this is a browser bug. In the meantime my extension causes the chrome tabs to switch noticeably slower, that it used to be. It now takes a couple of seconds to change the tab. So I'm looking for a workaround.

Any ideas how to fix this?

like image 792
Sergey K Avatar asked Jun 02 '21 14:06

Sergey K


2 Answers

The only solution that I have found so far is to put my handlers in a timeout like this:

chrome.tabs.onActivated.addListener((activeInfo) => {
        setTimeout(() => {
           // The old listener handler moves here
        }, 100);
    });

But there must be a better way, right?

like image 71
Sergey K Avatar answered Sep 18 '22 15:09

Sergey K


You will still get errors but at least it will work

chrome.tabs.onActivated.addListener(function(activeInfo) {getActivatedTab();});
function getActivatedTab(){
    chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
        try{
            if(tabs[0]!=undefined){
            
                console.log(tabs[0].url);   
            }
        }
        catch(err){
            setTimeout(function() {
            getActivatedTab();
            },100);
        }
    })
}
like image 29
Marinko Avatar answered Sep 16 '22 15:09

Marinko