All files / src/utils window.ts

93.1% Statements 27/29
80% Branches 4/5
100% Functions 2/2
93.1% Lines 27/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40    1x 1x 1x 1x   1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   2x 2x 2x 1x   2x       1x 1x 1x 1x 1x   1x 2x  
import type { Page } from 'playwright';
 
const BACKGROUND_WINDOW_WIDTH = 480;
const BACKGROUND_WINDOW_HEIGHT = 320;
const BACKGROUND_WINDOW_X = 3000;
const BACKGROUND_WINDOW_Y = 3000;
 
export function createBackgroundWindowLaunchOptions(): {
  headless: false;
  viewport: null;
  args: string[];
} {
  return {
    headless: false,
    viewport: null,
    args: [
      `--window-size=${BACKGROUND_WINDOW_WIDTH},${BACKGROUND_WINDOW_HEIGHT}`,
      `--window-position=${BACKGROUND_WINDOW_X},${BACKGROUND_WINDOW_Y}`,
    ],
  };
}
 
export async function makeWindowUnobtrusive(page: Page): Promise<void> {
  try {
    const session = await page.context().newCDPSession(page);
    const window = (await session.send('Browser.getWindowForTarget')) as { windowId?: number };
 
    if (typeof window.windowId !== 'number') {
      return;
    }
 
    await session.send('Browser.setWindowBounds', {
      windowId: window.windowId,
      bounds: { windowState: 'minimized' },
    });
  } catch {
    // The offscreen/tiny launch args are already applied. Minimize is best-effort.
  }
}