Capture of Chrome pages is not possible when the extension has not been activated on the current page due to the absence of the activeTab permission

Hey there!

I've encountered a tricky situation while trying to implement a Google extension. Due to technical limitations, I need to open the extension in a separate window as opposed to a disappearing pop-up, which is causing some issues with the functionality. Unfortunately, I'm facing an error when attempting to capture sound from this separate window:

"Error when capturing a tab. Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured."

I've gone through various responses on similar topics but haven't been able to find a solution that works or that I can fully grasp. Other extensions like Volume Recorder Online have the capabilities I require, but their code is obfuscated, making it challenging to understand why they work and mine doesn't.

Any assistance would be greatly appreciated. Below is the code I'm working with:

Manifest v3:

{
    "update_url": "https://clients2.google.com/service/update2/crx",
    
        "name": "AnyTalk",
        "version": "1.0.1",
        "manifest_version": 3,
        "minimum_chrome_version": "114",
        "background": {
            "service_worker": "scripts/window.js"
        },
        "icons": {
            "16": "assets/icon-16.png",
            "32": "assets/icon-32.png",
            "48": "assets/icon-48.png",
            "128": "assets/icon-128.png"
        },
        "action": {
            "default_icon": "assets/icon-128.png",
            "default_title": "AnyTalk"
        },
        "permissions": [
            "tabCapture",
            "downloads",
            "storage",
            "activeTab",
            "system.display",
            "tabs"
        ],
        "host_permissions": [
            "<all_urls>"
        ]
    }

window.js (background) \ Opens extension window and sends current tabid in query

chrome.action.onClicked.addListener(function(tab) {
  var tabId = tab.id;
  chrome.windows.create({
      url: '../views/recorder.html?tabId=' + tabId,
      type: 'popup',
      width: 400,
      height: 500
  }); 
});

recorder.js

let recordingEnabled = false;
let socket = null;
let recorder = null;


function getQueryParam(param) {
    console.log('Executing getQueryParam function');
    var urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(param);
}
let tabId = parseInt(getQueryParam("tabId"));

document.addEventListener('DOMContentLoaded', function () {
    console.log('DOMContentLoaded event listener triggered');
    var statusCircle = document.getElementById('status-circle');
    
    statusCircle.addEventListener('click', async function() {
        console.log('statusCircle click event listener triggered');
        if (recordingEnabled) {
            console.log('Recording is enabled. Stopping recording...');
            recordingEnabled = false;
            statusCircle.style.backgroundColor = 'blue';
            stopRecording();
        } else {
            console.log('Recording is disabled. Starting recording...');
            recordingEnabled = true;
            statusCircle.style.backgroundColor = 'red';
            captureTab(tabId);
        }
    });
});
function captureTab(tabId) {
    console.log('Executing captureTab function');

    console.log(typeof(tabId))
    chrome.tabs.update(tabId, { active: true }, function(tab) {
        if (chrome.runtime.lastError) {
            console.error('Error when updating a tab', chrome.runtime.lastError.message);
            return;
        }
        console.log('Tab updated:', tab);

        var captureOptions = { audio: true, video: false };
        chrome.tabCapture.capture(captureOptions, function(stream) {
            console.log('Tab captured:', stream);
            if (chrome.runtime.lastError) {
                console.error('Error when capturing a tab ', chrome.runtime.lastError.message);
                return;
            }

Check out the log results here

Answer №1

I stumbled upon the solution. It turns out that in order to record audio from a tab or window, rather than a popup, you need to utilize chrome.tabCapture.getMediaStreamId along with navigator.mediaDevices.getUserMedia (using chromemediasource "tab"). Once you do this, everything should function as intended!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How do I go about updating my code for welcome messages from discord.js v12 to v13?

While watching a YouTube tutorial on welcome messages, I decided to copy the entire code. However, when I tried using this code with discord.js v13, it didn't work. Strangely enough, everything seemed to function perfectly fine with discord.js v12. In ...

Preserving intricate nesting in a Mongoose schema

I've encountered a problem when trying to save nested subdocuments - I'm not certain if it's because they're not in an array or some other reason. The docs suggest that nested objects should be auto-saved, but that doesn't seem to ...

Tips for styling the json response received from a servlet with jquery ajax

I am attempting to display a list of users returned from a servlet using jQuery ajax. The first script block is functioning well, successfully presenting the list of users in a formatted manner but experiencing issues passing form parameters such as text a ...

What is the best method for purging a previously stored variable from the cache when making an Ajax call and simultaneously passing a

I am encountering an issue with variable loading during the ajax call. Upon clicking, I pass a variable to the ajax call which then sends the value to a PHP script. The data obtained is from: rnc.csv DLRNC01 DLRNC02 DLRNC03 DLRNC04 DLRNC05 DLRNC06 DLR ...

"Embedding PHP code within HTML tags, which is then embedded within

Running into an issue within a while loop... echo 'var contentString = '<div id="content" > <div id="bodyContent"> <p>' + $row[name]+ '</p> ...

When you hit the enter key in a text input field in JavaScript, it triggers a specific function

http://codepen.io/abdulahhamzic/pen/YqMQwB Is there a way to make it so that when I hit the enter key on a text input, it triggers a specific function? I attempted to achieve this using the following code: <input type="text" onkeypress=" ...

Is it possible for me to utilize a validation function to display error messages within a specific span id tag?

document.getElementById("button1").addEventListener("click", mouseOver1); function mouseOver1(){ document.getElementById("button1").style.color = "red"; } document.getElementById("button2").addEventListener("click", mouseOver); function mous ...

How can we avoid repeated evaluations by using memoization in a function?

Currently, I am working on a jQuery function designed to switch HTML elements based on specific viewports. The concept is quite simple: <div data-swap-for="#element" data-swap-on="phone"></div> This code snippet will insert the element with t ...

The static folder in Express server is failing to serve files

I have an application with certain static files that I want to send to the client, however the server is not sending them. app.use(express.static(__dirname, '/public')); I need help fixing this particular code snippet. ...

Can you elaborate on the contrast between React Server Components (RSC) and Server Side Rendering (SSR)?

I'm curious about the differences between RSC in React 18 and SSR in NextJS. Can anyone explain? ...

Creating a table in React.js by mapping array data from console.log output

I am working with an API that returns an array of results when called using axios.get(). I am trying to map this array into a table in a React JS application. Here is the code for fetching data from the API: const [data, getData] = useState([]) u ...

Exploring the world of CouchDB through jQuery and AJAX POST requests while navigating

I am in the process of building a simple web application. Today, I installed Couch 1.3.1 and set up a database. I am currently trying to save a document to my local Couch (localhost:5984) using a POST request from a client browser that is also on localhost ...

Sending an email through Node.js with SendGrid is not a challenge

I've got this Mailer.js file const sendgrid = require('sendgrid'); const helper = sendgrid.mail; const keys = require('../config/keys'); class Mailer extends helper.Mail { constructor({ subject, recipients ...

Google charts appear only after the second request, not on the initial one

Utilizing Google charts to visually represent company performance data. The Javascript code I have written is as follows: <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> go ...

What is the best way to verify multiple email addresses simultaneously?

Is there a method to validate multiple email addresses entered by users in a textarea? My current approach involves using ng-pattern for validation. ...

Maintaining Flexbox layout without triggering item re-rendering for a new container

This is the unique layout I'm aiming to create: I am facing a challenging flexbox layout that needs to be implemented. One of the items in this layout is a Webgl player, which cannot be conditionally rendered due to the restarting issue it may cause. ...

Unlimited Possibilities in Designing Shared React Components

Seeking the most effective strategies for empowering developers to customize elements within my React shared component. For example, I have a dropdown and want developers to choose from predefined themes that allow them to define highlight color, font siz ...

The function document.getElementById(...) is failing to retrieve the text data from the table as expected

Greetings fellow HTML and JavaScript novice! I've got a table with input cells in the bottom row: <table class="convtbl" id="table1"> <tr> <td>Distance 1 (in miles)</td> <td>Time ...

Using Geolocation in HTML5 and JavaScript

Currently, I am working on my debut mobile web application and have successfully integrated Google Maps into it using Geolocation JavaScript API version 3. Now, I am looking to add a button that, when clicked by the user, centers the map on my location o ...

Unable to insert hyperlinks into table rows within a React application

A React function was created by me to display a table. This is how the table appears. It accepts JSON as a parameter: { "id": 1, "firstName": "Richard", "lastName": "Morrison", "number ...