import { test } from "@playwright/test"; import { fileURLToPath } from "url"; import { dirname, join } from "path"; import os from "os"; import fs from "fs/promises"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const EXTENSION_PATH = join(__dirname, "..", "dist"); test.describe("Extension SW Diagnostic", () => { test("diagnostic - check if SW starts with devtools", async () => { const { chromium } = await import("playwright"); const userDataDir = join(os.tmpdir(), `peach-diag2-${Date.now()}`); await fs.mkdir(userDataDir, { recursive: true }); const ctx = await chromium.launchPersistentContext(userDataDir, { headless: false, args: [ `--load-extension=${EXTENSION_PATH}`, `--disable-extensions-except=${EXTENSION_PATH}`, ], }); await new Promise(r => setTimeout(r, 8000)); const sws = ctx.serviceWorkers(); const pages = ctx.pages(); console.log("=== DIAGNOSTIC RESULTS ==="); console.log(`Service workers: ${sws.length}`); console.log(`Pages: ${pages.length}`); console.log(`Page URLs: ${pages.map(p => p.url()).join(", ")}`); console.log(`SW URLs: ${sws.map(s => s.url()).join(", ")}`); if (sws.length > 0) { const sw = sws[0]; const extId = new URL(sw.url()).host; console.log(`Extension ID: ${extId}`); const popup = await ctx.newPage(); await popup.goto(`chrome-extension://${extId}/src/popup/index.html`); await popup.waitForTimeout(3000); console.log(`Popup URL: ${popup.url()}`); console.log(`Popup title: ${await popup.title()}`); } await ctx.close(); }); });