SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
357 stars 114 forks source link

Mute the browser audio #121

Closed SaadAI2 closed 1 year ago

SaadAI2 commented 1 year ago

async function videoRecorder() { const {getStream,launch}=require("puppeteer-stream"); const puppeteer = require("puppeteer-extra"); const fs = require("fs"); const StealthPlugin = require("puppeteer-extra-plugin-stealth"); puppeteer.use(StealthPlugin()); const filename = ./test.webm;

const file = fs.createWriteStream(filename);
let url= "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

const browser = await launch({
//  executablePath:'/usr/bin/google-chrome',
//  "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
  headless: false,
  args: [
    // "--headless=new",
    // "--use-fake-ui-for-media-stream",
    "--use-fake-device-for-media-stream",
],
executablePath: puppeteer.executablePath(),

});

const page = await browser.newPage();
await page.goto(url);

const stream = await getStream(page, { audio: true, video: false });
 console.log(stream)

}

videoRecorder() I am attempting to capture an audio stream for a YouTube video. However, when the browser initiates the stream capture, it mutes the video sound and returns a null stream.

SaadAI2 commented 1 year ago

PuppeteerReadableStream { _readableState: ReadableState { objectMode: false, highWaterMark: 8388608, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: [], flowing: true, ended: false, endEmitted: false, reading: true, constructed: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, errorEmitted: false, emitClose: true, autoDestroy: true, destroyed: false, errored: null, closed: false, closeEmitted: false, defaultEncoding: 'utf8', awaitDrainWriters: null, multiAwaitDrain: false, readingMore: false, dataEmitted: false, decoder: null, encoding: null,

}, _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, opts: { onDestroy: [Function: onDestroy], highWaterMarkMB: 8, immediateResume: true, port: 55200 }, onDestroy: [Function: onDestroy], tcpSockets: [ Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, _writableState: [WritableState], allowHalfOpen: false, _sockname: null, _pendingData: null, _pendingEncoding: '', server: [Server], _server: [Server],

  [Symbol(kHandle)]: [TCP],
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kSetNoDelay)]: false,
  [Symbol(kSetKeepAlive)]: false,
  [Symbol(kSetKeepAliveInitialDelay)]: 0,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
}

], tcpServer: <ref 1> Server { _events: [Object: null prototype] { connection: [Function (anonymous)] }, _eventsCount: 1, _maxListeners: undefined, _connections: 1, _handle: TCP { reading: false, onconnection: [Function: onconnection], [Symbol(owner_symbol)]: [Circular 1] }, _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: false, pauseOnConnect: false, noDelay: false, keepAlive: false, keepAliveInitialDelay: 0, _connectionKey: '4:127.0.0.1:55200',

[Symbol(async_id_symbol)]: 2820

},

} This is output i am getting from above code.

SamuelScheit commented 1 year ago

The chrome tab capturer mutes the tab, if it is being recorded. (that is normal behavior) The stream is not null, the log you've sent is the PuppeteerReadableStream, which is the expected return type. Have a look at the example to see how you can use the stream.