puppeteer / puppeteer

Node.js API for Chrome

Home Page:https://pptr.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Requested device not found` when using `chrome.tabCapture.capture`

s16h opened this issue · comments

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.11.0
  • Platform / OS version: MacOS Mojave 10.14.1
  • URLs (if applicable):
  • Node.js version: v10.12.0

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. Create a Chrome extension that uses chrome.tabCapture.capture in background.js:
// background.js

function startRecording() {
    chrome.tabCapture.capture(options, stream => {
        if (stream === null) {
            console.log(`Last Error: ${chrome.runtime.lastError.message}`);
            return;
        }
        try {
            const recorder = new MediaRecorder(stream);
        } catch (err) {
            console.log(err.message);
            return;
        }
        recorder.addEventListener('dataavailable', event => {
            console.log(`Got another blob.`);
        });
        const timeslice = 60 * 1000;
        recorder.start(timeslice);
    });
}
  1. In the Puppeteer script, load the extension.

  2. In the Puppeteer script, make sure you're listening to console events:

const targets = await browser.targets();
const backgroundPageTarget = targets.find(target => target.type() === 'background_page' && target.url().startsWith('chrome-extension://abcde/'));
const backgroundPage = await backgroundPageTarget.page();

backgroundPage.on('console', msg => {
    for (let i = 0; i < msg.args().length; ++i) {
        console.log(`${i}: ${msg.args()[i]}`);
    }
});
  1. In the Puppeteer script, access the extension's background page, and invoke the function in background.js that calls chrome.tabCapture.capture:
...

const test = await backgroundPage.evaluate(() => {
    startRecording();
    return Promise.resolve(42);
});

...

What is the expected result?

I would expect to start seeing a series of Got another blob.s outputted to the console. In other words, a non-null stream parameter.

What happens instead?

Last Error: Requested device not found gets outputted to the console. In other words, the stream parameter of chrome.tabCapture.capture's callback is null.

@s16h any chance you can provide us with a tiny github repo that reproduces this? This will save a ton of time.

@s16h awesome, thanks. This happens because extension is not marked as invoked; we'll need to add some protocol support for this.

@aslushnikov I thought whitelisting the extensions would mean I can use chrome.tabCapture.capture without having to invoke the extension. In the test repo, if you remove the whitelist flag, then the error does indeed mention that the extension needs to be invoked; do give it a try. But when the whitelist flag is added back, the error then becomes Requested device not found. Is this just a case of a non-descriptive error then?

Another thing I have also tried: while Chromium is running in headful mode (using same test.js script), I add a few seconds of wait before going into the background page. During that wait, I manually invoke the extension myself, with the mouse, but I still get Requested device not found. Does that make sense?

@s16h hmm looks like my diagnose is wrong then! Can you please try using Chrome instead of Chromium? (note: be sure to pick appropriate pptr version - check out the compatibility table in https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md)

@aslushnikov just tried with Chrome (71.0.3578) and Puppeteer (1.9.0 and 1.11.0); same story: Requested device not found

In case it's helpful, searching for that error in the Chromium source code landed me here: https://github.com/chromium/chromium/blob/2ca8c5037021c9d2ecc00b787d58a31ed8fc8bcb/third_party/blink/renderer/modules/audio_output_devices/set_sink_id_callbacks.cc#L19 🤷‍♂️not that I know what it fully means but perhaps it's struggling to find an output audio sink?

perhaps it's struggling to find an output audio sink?

@s16h thanks for checking with chrome stable. Looks like there are issues with either audio or video sinks - let me debug this further to see what's going on.

Let me know if there's anything I can do to help, @aslushnikov. This is a huge blocker, so, I'm more than willing to spend cycles on it.

I'm still investigating further but it seems to be that removing --use-fake-ui-for-media-stream resolves the issue.

@aslushnikov, removing the --use-fake-ui-for-media-stream flag solved this.

@s16h oh looks like you've figured it out. Thanks!

For the record: the puppeteer-tab-capture-repro repository now has a demo of extension that initiates screen recording.