-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpuppeteer.mjs
38 lines (35 loc) · 1.38 KB
/
puppeteer.mjs
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
import { createProxyMiddleware } from 'http-proxy-middleware';
import {default as puppeteer} from 'puppeteer';
const localmode = process.env.LOCAL || false;
let uid = 0;
export const puppeteerProxy = createProxyMiddleware('/', {
ws: true,
router: async function(req) {
let browser = null;
req.on('close', async function (err) {
if (browser && !localmode) {
await browser.close(); browser = undefined;
}
});
browser = await puppeteer.launch({
...(process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD && {executablePath: 'google-chrome-stable'}),
devtools: localmode,
args: [
`--proxy-server=127.0.0.1:8888`,
`--disk-cache-dir=/tmp/${uid}`,
`--media-cache-dir=/tmp/${uid++}`,
`--media-cache-size=0`,
`--disk-cache-size=0`,
'--no-sandbox', // Not necissary if running with --cap-add=SYS_ADMIN
'--no-zygote',
'--disable-gpu',
'--mute-audio',
'--disable-dev-shm-usage',
'--disable-web-security', // Turn off CORS
`--user-agent=observablehq.com/@endpointservices/puppeteer`
]
});
console.log("redirecting to " + browser.wsEndpoint())
return browser.wsEndpoint();
}
});