Skip to content

Instantly share code, notes, and snippets.

@rajatbarman rajatbarman/test.js
Created Oct 11, 2019

Embed
What would you like to do?
const puppeteer = require('puppeteer');
const Xvfb = require('xvfb');
const xvfb = new Xvfb({ reuse: true });
const width = 3840;
const height = 2160;
const options = {
headless: false,
args: [
'--enable-usermedia-screen-capturing',
'--allow-http-screen-capture',
'--auto-select-desktop-capture-source=puppetcam',
'--load-extension=' + __dirname, ,
'--disable-extensions-except=' + __dirname,
'--disable-infobars',
`--window-size=${width},${height}`,
'--disable-dev-shm-usage',
],
};
async function record() {
const session_id = process.argv[2];
const time_to_record_minutes = parseInt(process.argv[3]) || 60;
const total_waiting_in_milliseconds = time_to_record_minutes * 60 * 1000;
if (!session_id) {
console.log('Please provide a session_id');
return;
}
xvfb.startSync();
const classId = session_id;
const filename = `${classId}.webm`;
const browser = await puppeteer.launch(options);
const pages = await browser.pages();
const page = pages[0];
// page.on('console', msg => {
// for (let i = 0; i < msg.args().length; ++i)
// console.log(`${i}: ${msg.args()[i]}`);
// });
await page._client.send('Emulation.clearDeviceMetricsOverride');
await page.goto(`https://www.youtube.com/watch?v=CvSv5lV3v8c`, { waitUntil: 'networkidle2', timeout: 0 });
// await page.setCookie(userTokenCookie, vcIdCookie);
// await page.reload({ timeout: 0 });
console.log(`
Successfully running recording ${classId} till ${time_to_record_minutes} minutes.
`);
await page.waitFor(total_waiting_in_milliseconds);
console.log(`
Successfully finished recording for ${classId}
`);
await page.evaluate(({ filename, total_waiting_in_milliseconds }) => {
window.postMessage({ type: 'SET_EXPORT_PATH', filename }, '*')
window.postMessage({ type: 'REC_STOP', video_duration_ms: total_waiting_in_milliseconds }, '*')
}, { filename, total_waiting_in_milliseconds })
// Wait for download of webm to complete
await page.waitForSelector('html.downloadComplete', { timeout: 0 })
await page.close();
await browser.close()
xvfb.stopSync()
}
record();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.