# browser.tabs.captureVisibleTab not working in firefox for mv3

**URL:** <https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965>\
**Category:** Development\
**Created:** [September 28, 2023, 9:41am UTC](https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965 "2023-09-28T09:41:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NEELABH\_NAGAICH](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/neelabh_nagaich/32/63534_2.png) [@NEELABH\_NAGAICH](https://discourse.mozilla.org/u/NEELABH_NAGAICH)\
**Post date:** [September 28, 2023, 9:41am UTC](https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965/1 "2023-09-28T09:41:25Z")

</div>

browser.tabs.captureVisibleTab is undefined in firefox manifest v3, even after adding “\<all\_urls\>” under host\_permissions and “activeTab” under permissions.  
Any help would be appreciated if I am missing something.

---

<div class="post-metadata">

**Author:** ![hans\_squared](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/hans_squared/32/67424_2.png) [@hans\_squared](https://discourse.mozilla.org/u/hans_squared)\
**Post date:** [September 28, 2023, 7:03pm UTC](https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965/2 "2023-09-28T19:03:44Z")

</div>

It’s a permission problem:  
Firefox MV3 treats all host permissions as optional.

You need to jump through a few hoops to use tabs.captureVisibleTab()

1. Install the test extension:  
[captureVisibleTab.zip](https://discourse.mozilla.org/uploads/short-url/nUczfhEbLwVYgOuRGvRHaDBWU3j.zip) (1.5 KB)

2. Click the action icon to download a screenshot of the active tab.  
Because the extension doesn’t have the “\<all\_urls\>” permissions yet, the extension console displays:  
`TypeError: browser.tabs.captureVisibleTab is not a function`  
Enable the “\<all\_urls\>” permission in the Add-ons Manager:  

3. Click the action icon again.  
Again, the extension console displays:  
`TypeError: browser.tabs.captureVisibleTab is not a function`  
Reload the extension:  

4. Click the action icon again.  
The extension now creates the file “captureVisibleTab.png” in the Downloads directory.  

Notes:

- For the sake of simplicity, the test extension forces the user to enable the “\<all\_urls\>” permissions manually, and reload the extension manually. A finished extension could do this with browser.permissions.request() and browser.runtime.reload()
- I don’t know why you have to reload the extension after enabling the “\<all\_urls\>” permissions.  
If you think this is a bug, please consider reporting it on [https://bugzilla.mozilla.org/](https://bugzilla.mozilla.org/)
- I don’t know if Firefox will distinguish between required and optional host permissions once the “optional\_host\_permissions” manifest key has been implemented.  
See [manifest.json \> optional\_permissions \> Host permissions](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions#host_permissions)
- browser.tabs.captureVisibleTab() returns a [data URL](https://developer.mozilla.org/en-US/docs/web/http/basics_of_http/data_urls).  
Firefox 118.0 can’t download data URLs, so the test extension converts the data URL to a blob, then converts the blob to an object URL, and downloads the object URL.

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [September 28, 2023, 7:51pm UTC](https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965/3 "2023-09-28T19:51:52Z")

</div>

This may be a good time to mention that there is also an issue to allow screenshots with “activeTab” only permission (same as in Chrome and Safari).

> **[1784920 - Add \`activeTab\` as permission for \`tabs.captureVisibleTab\` API](https://bugzilla.mozilla.org/show_bug.cgi?id=1784920)**
>
> NEW (nobody) in WebExtensions - General. Last updated 2023-02-20.

---

<div class="post-metadata">

**Author:** ![NEELABH\_NAGAICH](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/neelabh_nagaich/32/63534_2.png) [@NEELABH\_NAGAICH](https://discourse.mozilla.org/u/NEELABH_NAGAICH)\
**Post date:** [September 29, 2023, 7:27am UTC](https://discourse.mozilla.org/t/browser-tabs-capturevisibletab-not-working-in-firefox-for-mv3/122965/4 "2023-09-29T07:27:03Z")

</div>

thanks Hans, it worked, and I was able to automate these permissions using browser.permissions.request({origins: [’\<all\_urls\>’]})
