captureVisibleTab()
when I use
chrome.tabs.captureVisibleTab()
I get this error Error: Either the '<all_urls>' or 'activeTab'
permission is required. but I have both of those permissions in the manifest.json50 Replies
@avi12
Did you try to have only
activeTab
?
I didn't specifically use captureVisibleTab
, but I did use other tab functions in the past
Oh wait
What's your manifest?
I'm assuming you're trying to run the function from background.ts
yes
yes
?
just default with the activeTab permission
So
Try to change it to
I tried that already
That's my manifest
@Execade
Doesn't work for me, still the same error
I was able to capture a tab with this exact code
Try to reload the extension
That goes into
background.ts
now it got this error
Tabs cannot be edited right now (user may be dragging a tab).
GitHub
GitHub - avi12/test-capture-visible-tab
Contribute to avi12/test-capture-visible-tab development by creating an account on GitHub.
@Execade Let me know once you've figured it out 🙂
well something must have been on the wrong version
@Execade has reached level 3. GG!
when I copied the dependencies from you it works
is it because I didn't have
web-ext
?Everything's possible with Plasmo 😁
A few days ago I pushed an update to my 100K extension come on that day I was able to run
Then today I pursued updating another extension of mine, but discovered that this exact command breaks
After a few hours of banging my head, I discovered that the issue was the Plasmo version, which surprisingly didn't cause an issue on the popular extension
Nope,
web-ext
is simply a tool by Mozilla that makes it easy to debug and package extensions
You can just as easily install the extension on your daily driver Chrome and it should work the same
https://npm.im/web-extnpm
web-ext
A command line tool to help build, run, and test web extensions. Latest version: 7.5.0, last published: a month ago. Start using web-ext in your project by running
npm i web-ext
. There are 26 other projects in the npm registry using web-ext.yeah sucks when something works and then it doesn't work anymore
That's why devs, and frontend devs in particular have high salaries 😁
wait nvm it doesn't work
How are you trying to capture the tab?
CSUI? Popup?
chrome.action
?
I'm pretty sure captureVisibleTab()
must run in the background scripthuh when I put it in a command it works
So if you're trying to capture from a popup/content script, you'd need to ping the background first, e.g.
NGL I don't 100% remember the
chrome.tab.query
APII wanted to put it in
onActivated
but that doesn't work I guessWdym?
Send here the snippet you've tried
just the capture function inside the onActivated event I can send it tomorrow
I was able to get it to work with
onActivated
when used <all_urls>
Though keep in mind that if you're using onActivated
alone, from my experience it only works when navigating between tabs, i.e. it doesn't trigger when clicking a URLIf you want it to trigger when clicking a URL, you need to add a
onUpdated
listener
https://developer.chrome.com/docs/extensions/reference/tabs/#event-onUpdatedI updated the code here
now I found a workaround how to make it work all the time
TBH you shouldn't use
setTimeout
unless this is your last resort, as it could result in unintended consequences
Check out https://youtu.be/8eHInw9_U8k for more infoGoogle Chrome Developers
YouTube
Scheduling Tasks - HTTP 203
Tasks, microtasks, nanotasks... JavaScript has it all. Or maybe not. What are they? How do you use them? What do they even mean? Surma rips off Jake’s event loop talk and tells you all about scheduling callback functions in JavaScript.
Jake’s event loop talk → https://goo.gle/jake-event-loop
JavaScript Counters the Hard Way → https://goo.gle/3...
It's better to extract the anonymous function into a named one and reuse it in multiple listeners so your code becomes predictable
Like
makes sense
Lmk what progress you've made
Right now I'm on my phone as it's almost 2:00 a.m. 🙃
good night 🙂
How's your progress? Did you/are you going to remove the
setTimeout
?currently I got stuck on another problem where saving the image doesn't work
Use chrome.downloads
hey folks @avi12 @Execade , I've just been running into the same-ish issues. I'm trying to capture the tab when that tab's CS sends a message to the SW. Turns out you need
<all_urls>
host permission for that, and not just the activeTab
permission. Apparently, the activeTab
is only sufficient if the user invokes the extension directly.AFAIK
<all_urls>
and activeTab
are never needed at the same time
In fact, if you use the former it automatically includes the letter, because it implies that not only that you need to access the active tab but also every other possible domain
The downside of using the former is that if your extension is already published, it will cause the user's Chrome to disable it and prompt the user to manually re-enable it
Generally speaking, if you send a message from the content script to the background script while having activeTab
, you can manipulate that tab, as well as capture it, e.g.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureVisibleTabMDN Web Docs
tabs.captureVisibleTab() - Mozilla | MDN
Creates a data URL encoding the image of an area of the active tab in the specified window. You must have the or activeTab permission.
Interesting I recently remembered this
and somehow it works
I need both for it to work but don't ask why
not possible because you get the "user is dragging tab.." error
onUpdate works but only when the url changes
I literally tried this and it didn't work. I only want to capture the tab when a content script sends a message to the SW
Stack Overflow
Capture chrome tab without browse action
I have a simple method which captures current tab, and it works only when this method triggered by click on extension button (i.e. browserAction).
But when I use this method in setTimeout event it
This question is from 2016, might not be applicable to Manifest V3
I'll admit that I haven't actually tried, I typed it on my phone and assumed it works 😅
I coded a small extension to test it, and indeed I was not able to invoke the capture from the content script
Furthermore, this is what the documentation states:
In addition, I was only able to get a media stream ID with getMediaStreamId
Despite having
"permissions": ["tabCapture"]
, I wasn't able to call captureChrome for Developers
chrome.tabCapture | API | Chrome for Developers
Chrome for Developers
The "activeTab" permission | Chrome Extensions | Chrome for Dev...
How to use the activeTab permission in your Chrome Extension.
what error did you get? in some cases you need to use setTimeout as you cant capture instantly
To my understanding, according to the screenshot I shared, you cannot work around it; it's a limitation in the API
You will have to invoke the ext in one of the 4 aforementioned ways to take the screenshot
well it works for me
Can you make a repo to demonstrate a POC?