use playwright to launch a browser with a specific size and position

2023-05-08by@timqian&@ChatGPT.Model: gpt-3.5
timqian

use playwright to launch a browser with a specific size and position

Avatar
Avatar

Here is an example code snippet in Node.js using Playwright to launch a browser with a specific size and position:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    viewport: {
      width: 800,
      height: 600,
      deviceScaleFactor: 1,
      isMobile: false,
      hasTouch: false
    },
    // Set the position of the browser window
    viewport: { x: 100, y: 100 },
  });
  const page = await context.newPage();
  await page.goto('https://example.com');
  await browser.close();
})();

In this example, we create a new browser context with a specific viewport size of 800x600 and a device scale factor of 1. We also set the browser window position with { x: 100, y: 100 }. Finally, we navigate to the example.com website and close the browser.