Closed ppoturalskiEC closed 2 years ago
Can you show how you are calling the destroy function?
Sorry for delay.
Here is a part of code that creates instance, page, stream and then destroys the stream. Let me know if you need more details.
// Create page
const browser = await launch({
// @ts-ignore
product: 'chrome',
headless: false,
ignoreDefaultArgs: ['--mute-audio'],
args: [
'--autoplay-policy=no-user-gesture-required'
]
})
const page = await browser.newPage()
(...)
// Create stream
const tabStream = await getStream(page,
{
audio: true,
video: false
}
)
(...)
// Destroy stream
await tabStream.destroy()
I'm also having the same difficulty.
The node version is below.
node --version
v16.8.0
This is the code I wrote.
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import * as puppeteerStream from 'puppeteer-stream';
import fs = require('fs');
const file = fs.createWriteStream(__dirname + '/test.webm');
async function test() {
const options = {
headless: false,
args: ['--autoplay-policy=no-user-gesture-required'],
ignoreDefaultArgs: ['--mute-audio'],
};
const browser = await puppeteerStream.launch(options);
const page = await browser.newPage();
const url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
await page.goto(url);
// create a video stream
const streamOptions: puppeteerStream.getStreamOptions = {
audio: true,
video: true,
};
const stream = await puppeteerStream.getStream(page as any, streamOptions);
console.log('recording');
stream.pipe(file);
await timeout(5000);
file.close();
console.log('finished');
}
function timeout(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
void (async () => {
await test();
});
When I execute tsc --build
, I got the following error.
$ tsc --build
node_modules/puppeteer-stream/dist/PuppeteerStream.d.ts:8:5 - error TS2416: Property 'destroy' in type 'Stream' is not assignable to the same property in base type 'Readable'.
Type '(page?: Page) => Promise<void>' is not assignable to type '(error?: Error) => void'.
Types of parameters 'page' and 'error' are incompatible.
Type 'Error' is missing the following properties from type 'Page': _closed, _client, _target, _keyboard, and 118 more.
8 destroy(page?: Page): Promise<void>;
~~~~~~~
Found 1 error.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
node --version v16.13.0
Need to change destroy to destroyStream (for example) in files dist/puppeteerStream.d.ts line 8 and src/puppeteerStream.ts line 13
@Flam3rboy author?
fixed with fef0a6f
After upgrading to 2.0.7 from 2.0.6 I start getting this error from tsc:
I bypass it by chaning
destroy(page?: Page): Promise<void>;
todestroy(page?: any): Promise<void>;
in node_modules/puppeteer-stream/dist/PuppeteerStream.d.ts:8:5. However that's a dirty fix.Any ideas what could be wrong?