'chrome.tabCapture is undefined when extension icon is clicked
I am trying to use the chrome extension tabCapture API. To do this, I hooked up a simple background script that adds a click handler to the extension icon (via chrome.action
). The handler should start capturing the tab via a simple call to chrome.tabCapture.capture
. However, tabCapture
is undefined. The full source consists of two files. The contents are shown below.
manifest.json
{
"name": "tab capture test",
"description": "Manifest v3 tab capture test",
"version": "1.0.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions":[
"storage",
"activeTab",
"tabCapture",
"scripting"
],
"action": {}
}
background.js
chrome.action.onClicked.addListener((tab) => {
chrome.tabCapture.capture(
{
video: true,
},
(stream) => {
console.log(stream)
}
)
})
This results in an error when I click the extension icon.
Error in event handler: TypeError: Cannot read properties of undefined (reading 'capture')
Why might tabCapture
be undefined?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|