camoufox
Version:
JavaScript port of Camoufox - a tool for Firefox anti-fingerprinting and browser automation.
31 lines (30 loc) • 1.37 kB
JavaScript
import { firefox } from 'playwright-core';
import { launchOptions, syncAttachVD } from './utils.js';
import { VirtualDisplay } from './virtdisplay.js';
import { checkBrowser } from './browser.js';
export async function Camoufox(launch_options) {
const { headless, ...launchOptions } = launch_options;
await checkBrowser(launchOptions);
// console.log(launchOptions.executable_path)
return NewBrowser(firefox, headless, {}, false, false, launchOptions);
}
export async function NewBrowser(playwright, headless = false, fromOptions = {}, persistentContext = false, debug = false, launch_options = {}) {
let virtualDisplay = null;
if (headless === 'virtual') {
virtualDisplay = new VirtualDisplay(debug);
launch_options['virtual_display'] = virtualDisplay.get();
launch_options.headless = false;
}
else {
launch_options.headless ||= headless;
}
if (!fromOptions || Object.keys(fromOptions).length === 0) {
fromOptions = await launchOptions({ debug, ...launch_options });
}
if (persistentContext) {
const context = await playwright.launchPersistentContext('~/.crawlee/persistent-user-data-dir', fromOptions);
return syncAttachVD(context, virtualDisplay);
}
const browser = await playwright.launch(fromOptions);
return syncAttachVD(browser, virtualDisplay);
}