3

I try to update Manifest Version from 2 to 3. And chrome.tabs.captureVisibleTab throw error

Unchecked runtime.lastError: Either the '<all_urls>' or 'activeTab' permission is required.

As '<all_urls>' is not available in Manifest 3, I declared the 'activeTab' permission. But it doesn't work.

As My code in Background.ts

export const getCapture = (): Promise<string> => {
  return new Promise((resolve) => {
    chrome.tabs.captureVisibleTab((dataUrl) => resolve(dataUrl));
  });
};

Manifest.json

{
  ...,
  "permissions": [
    "contextMenus",
    "tabs",
    "activeTab"
  ],
}

So how can I use this api to take a screenshot in Manifest 3? Or should I use another api?

QC CAI
  • 131
  • 1
  • 6

1 Answers1

1

There is two ways to use chrome.tabs.captureVisibleTab:

  1. declare '' permission but it was abandon in Manifest V3.

  2. declare 'activeTabs' permission. But it only work when the user invokes the extension as Chrome Extension Docs mentioned. So if you use chrome.tabs.captureVisibleTab directly, it throw error.

QC CAI
  • 131
  • 1
  • 6
  • 3
    `` is available in MV3. It should be declared in `host_permissions`. See the [migration guide](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/). – wOxxOm Jan 04 '22 at 05:36