Chrome extension - why 'catch' does not execute?

I am using an example from chrome developer site
but the catch, does not execute
what is wrong?

    /// background.js
    chrome.tabs.onActivated.addListener(activeInfo => move(activeInfo));
    async function move(activeInfo) {
      try {
        await chrome.tabs.move(activeInfo.tabId, {index: 0});
      } catch (error) {
        if (error == 'Error: Tabs cannot be edited right now (user may be dragging a tab).') {
          setTimeout(() => move(activeInfo), 50);

catch only executes if chrome.tabs.move() throws an error. Is this logging “Success.” in the console? If so then no error is occurring and the code in the catch block will never execute.

If an error is being thrown then the code in the catch block only executes if the if condition is true. You could add


to the beginning of the catch block and then you would be able to verify that the catch executed if there was indeed an error. And you could also verify what the variable error actually contains to make sure it matches what you are expecting in the if statement.

1 Like

thank you
I did that, and catch did not execute,
chrome.tabs.move() does not always execute, and I get in browser’s extension tab, the same error that is listed in the catch
that is the problem

If the error in the catch is the exact string that the if statement is looking for then it just calls itself again in 50ms, so it should just keep trying until the error doesn’t occur. Without actually testing this I can’t really give you any useful help. I suppose you could copy the exact errors from the console into this thread so I could see them for myself.

OK, the problem was manifest V2 instead V3

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.