-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbrowser.js
More file actions
26 lines (20 loc) · 798 Bytes
/
browser.js
File metadata and controls
26 lines (20 loc) · 798 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
import { chromium } from "playwright";
import path from "path";
export const display_width = 800;
export const display_height = 800;
export async function launchBrowser(saveHar) {
const browser = await chromium.launch({
headless: false,
chromiumSandbox: true,
env: { DISPLAY: ":0" },
args: [`--window-size=${display_width},${display_height}`, "--disable-extensions", "--disable-file-system"],
});
const timestamp = Date.now();
const harPath = path.join(process.cwd(), `cua-session-${timestamp}.har`);
const context = await browser.newContext({
recordHar: saveHar ? { path: harPath, content: "embed"} : undefined,
viewport: { width: display_width, height: display_height },
});
const page = await context.newPage();
return { browser, context, page};
}