Why does chrome.tabCapture.getMediaStreamId return an error for an active YouTube tab stating "Chrome pages cannot be c

I'm trying to capture the active YouTube tab using chrome.tabCapture.getMediaStreamId, but I'

I'm trying to capture the active YouTube tab using chrome.tabCapture.getMediaStreamId, but I'm getting an error saying:

chrome.tabCapture.getMediaStreamId error: Error: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.

Here is the relevant part of my code in popup.js:

document.getElementById("captureButton").addEventListener("click", async () => {
    console.log("Capture button clicked");

    const [activeTab] = await chrome.tabs.query({ active: true, currentWindow: true });
    if (!activeTab?.id) {
        console.error("No active tab found");
        return;
    }
    console.log("Active tab:", activeTab.url);

    try {
        const streamId = await chrome.tabCapture.getMediaStreamId({
            targetTabId: activeTab.id,
        });

        if (!streamId) {
            console.warn("No streamId was returned.");
            return;
        } else {
            console.log("Got MediaStreamId:", streamId);
        }
    } catch (err) {
        console.error("chrome.tabCapture.getMediaStreamId error:", err);
    }
});

The log shows that the active tab URL is /, but I still get the error:

chrome.tabCapture.getMediaStreamId error: Error: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.

I have already added the following permissions in my manifest.json:

{
    "manifest_version": 3,
    "name": "TabCapture Test",
    "version": "1.0",
    "permissions": [
      "tabCapture",
      "activeTab",
      "tabs"
    ],
    "action": {
      "default_popup": "popup.html"
    }
  }
  

But it doesn’t seem to solve the problem. The error message mentions that "Chrome pages cannot be captured," but in this case, the active tab is YouTube, which is not a Chrome internal page.

Question: Why am I still getting this error even though the active tab is YouTube and how can I successfully get the streamId for a YouTube page using chrome.tabCapture? Are there additional permissions or settings required to make this work?

Any help or guidance is appreciated!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744723403a4590045.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信