-
Notifications
You must be signed in to change notification settings - Fork 63
/
export.js
46 lines (40 loc) · 1.48 KB
/
export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const puppeteer = require('puppeteer');
const Xvfb = require('xvfb');
var width = 1280;
var height = 720;
var xvfb = new Xvfb({silent: true, xvfb_args: ["-screen", "0", `${width}x${height}x24`, "-ac"],});
var 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}`,
],
}
async function main() {
xvfb.startSync()
var url = process.argv[2], exportname = process.argv[3]
if(!url){ url = 'http://tobiasahlin.com/spinkit/' }
if(!exportname){ exportname = 'spinner.webm' }
const browser = await puppeteer.launch(options)
const pages = await browser.pages()
const page = pages[0]
await page._client.send('Emulation.clearDeviceMetricsOverride')
await page.goto(url, {waitUntil: 'networkidle2'})
await page.setBypassCSP(true)
// Perform any actions that have to be captured in the exported video
await page.waitFor(8000)
await page.evaluate(filename=>{
window.postMessage({type: 'SET_EXPORT_PATH', filename: filename}, '*')
window.postMessage({type: 'REC_STOP'}, '*')
}, exportname)
// Wait for download of webm to complete
await page.waitForSelector('html.downloadComplete', {timeout: 0})
await browser.close()
xvfb.stopSync()
}
main()