Launch a Playwright Context. If persistentContext is not true, also launch a Browser.
// launch a chrome browser and contextconst { browser, context } = await launch();// create a page in the context to use in our testconst page = await context.newPage();// slow down each action down by 2 secondsconst { context } = await launch({ slowMo: 2000 });// launch a webkit (safari) browser and contextconst { context } = await launch({ browser: "webkit" });// emulate an iphone to test a responsive site// full list of devices: https://github.com/microsoft/playwright/blob/v1.8.0/src/server/deviceDescriptors.jsconst { context } = await launch({ ...devices["iPhone 8"] });// emulate a camera and screen for testing recordingconst { context } = await launch({args: ["--use-fake-device-for-media-stream","--use-file-for-fake-video-capture=/root/files/wolf.mjpeg","--use-fake-ui-for-media-stream",],});// accept permission promptsconst { context } = await launch({permissions: ["clipboard-read", "clipboard-write", "geolocation"],});
You can use any option available on launch or newContext, including these commonly used ones:
[options] (Object)
[]
"chrome"
false
[]
0
Returns: Promise<{ browser?, context }>