The NewBrowser() function provides a lower-level way to initialize a browser by explicitly passing the Playwright browser type (e.g., firefox). This is useful if you need to control the specific Playwright engine or handle custom launch logic.
Parameters:
playwright: A BrowserType (typically firefox from playwright-core).headless: A boolean or the string 'virtual'. Using 'virtual' enables a VirtualDisplay to simulate a headed environment even in headless mode.fromOptions: An object used to override or provide additional launch configurations.userDataDir: A string path for a persistent context, or false for a non-persistent browser.debug: A boolean to enable debugging features.launch_options: An object of type LaunchOptions.
Return Value:
- Returns a
BrowserContext if userDataDir is a string. - Returns a
Browser if userDataDir is false.
import { NewBrowser } from 'camoufox-js';
import { firefox } from 'playwright-core';
const browser = await NewBrowser(
firefox,
'virtual', // Uses VirtualDisplay
{}, // fromOptions
false, // userDataDir
false, // debug
{ headless: true } // launch_options
);