Chrome.tabs.query crash

This code works

  ( async () =>{
       const [tab] = await browser.tabs.query({active: true, currentWindow: true});
       const response = await chrome.tabs.sendMessage( tab.id, {data: data, context: fcb_context, sel: sel});
       log(response);
   })();

and changing browser.tabs with chrome.tabs fails:

Uncaught (in promise) TypeError: undefined has no properties
moz-extension://3515db55-fef7-443b-baaa-0fef84f7ac7c/js/background.js:166and changing browser.tabs to chrome.tabs fails constantly witand changing browser.tabs to chrome.tabs fails constantly with

what the problem now ?

If I understand your question correctly, the problem is that you’re using the “chrome” namespace with Promises.

But I don’t know if this applies only to MV2, or also to MV3.

A complete example with a clearer problem description would be helpful in diagnosing the problem.

  • As a porting aid, the Firefox implementation of WebExtensions supports chrome , using callbacks, as well as browser , using promises.
  • If you choose to write your extension to use browser and promises, then Firefox also provides a polyfill that will enable it to run in Chrome

Yes but the strange thing is that it worked in the example I have posted last week and it doesn’t now…
In fact, no, it does not work with MV2 in this example neither (I only saw that the content script was loaded) but using the past menu gives the same error.
With MV3 in the manifest, I have to give the permission for the page, but the call succeed.

F

I would guess that tab is undefined :slight_smile:.
Put more console logs statements there to be sure.

If you execute this code in a console window that has no tabs, it will fail.
Regarding the browser/chrome, in the MV3 they should behave the same as long as you don’t provide callback parameter.