/* eslint-disable @typescript-eslint/no-require-imports */
const { chromium } = require('@playwright/test');
require('dotenv').config({ path: './.env.local' });
const fs = require('fs');
const path = require('path');

(async () => {
  const browser = await chromium.launch({
    headless: false,
    args: [
      '--disable-web-security',
      '--disable-features=IsolateOrigins,site-per-process',
    ],
  });

  const authStatePath = path.join(__dirname, 'auth-state.json');
  let storageState = undefined;

  if (fs.existsSync(authStatePath)) {
    console.log('Loading authentication state from file');
    storageState = authStatePath;
  } else {
    console.log('No auth state file found at', authStatePath);
  }

  const context = await browser.newContext({
    extraHTTPHeaders: {
      'x-vercel-protection-bypass':
        process.env.VERCEL_AUTOMATION_BYPASS_SECRET || '',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
      'Access-Control-Allow-Headers': 'Content-Type, Authorization',
      'Access-Control-Allow-Credentials': 'true',
    },
    storageState,
  });
  const page = await context.newPage();

  // Start recording
  await page.goto('about:blank');
  await page.goto('https://b.suno.fm/');
  await page.pause();
})();
