using Playwright's recordVideo option when using newContext

Hi everyone, thanks for the awesome platform. I am stuck on something and could use a hand. I am looking for a way to record videos of crawls in order to evaluate a playbook that executes during a visit but can't figure out how to pass options to enable video recording to crawlee as specified in Playwright's docs
const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });
const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });
Is there an example somewhere in the docs that I missed? The only instance of recordVideo I see is here https://crawlee.dev/api/browser-pool/class/PlaywrightPlugin#createController but I've no clue how to use it. Any help is much appreciated.
PlaywrightPlugin | API | Crawlee
The BrowserPlugin serves two purposes. First, it is the base class that specialized controllers like PuppeteerPlugin or PlaywrightPlugin extend. Second, it allows the user to configure the automation libraries and feed them to {@apilink BrowserPool} for use.
1 Reply
xenogeneic-maroon
xenogeneic-maroon3y ago
Hey @antwan - shared your question with the team, I am pretty sure it should be possible but it's not the most common use-case, so I would rather wait for their response So... Something like that should work:
const crawler = new PlaywrightCrawler({
browserPoolOptions: {
preLaunchHooks: [(_, launchContext) => {
launchContext.launchOptions.recordVideo = {
width: 800,
height: 600,
dir: '/your/path/to/the/dir/here',
};
}],
},
async requestHandler(context) {
context.log.info(context.request.url);
}
});

await crawler.run(['https://www.example.com']);
const crawler = new PlaywrightCrawler({
browserPoolOptions: {
preLaunchHooks: [(_, launchContext) => {
launchContext.launchOptions.recordVideo = {
width: 800,
height: 600,
dir: '/your/path/to/the/dir/here',
};
}],
},
async requestHandler(context) {
context.log.info(context.request.url);
}
});

await crawler.run(['https://www.example.com']);
I just tried it locally and it created some .webm files

Did you find this page helpful?