-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrender_html.js
More file actions
31 lines (27 loc) · 783 Bytes
/
Copy pathrender_html.js
File metadata and controls
31 lines (27 loc) · 783 Bytes
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
// Run with
// node render_html.js url output_file
'use strict';
const puppeteer = require('puppeteer');
const fs = require('fs');
(async function main() {
let browser;
try {
browser = await puppeteer.launch();
const page = await browser.newPage();
const url = process.argv[2];
const output_file = process.argv[3];
await page.goto(url);
// The load event can precede MathJax's asynchronous font loading/typesetting.
await page.evaluate(async () => {
await window.mathTypesetPromise;
await document.fonts.ready;
});
const html = await page.content();
fs.writeFileSync(output_file, html);
} catch (err) {
console.error(err);
process.exitCode = 1;
} finally {
if (browser) await browser.close();
}
})();