From adeaabd5aae65b4828fdd9c591ae1d89487e8fdb Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Tue, 3 Feb 2026 20:05:11 +0100 Subject: [PATCH] =?UTF-8?q?speed=20up=20list=20scripts=20test=20(10.5s=20?= =?UTF-8?q?=E2=86=92=201.4s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test was slow due to: 1. Page scanning by content (slow waitForLoadState + content() per page) 2. Using example.com which only has inline scripts with empty URLs Fix: - Use URL matching instead of content scanning (fast) - Use news.ycombinator.com which has scripts with actual URLs - The Debugger class filters out scripts without URLs, so we need a page that actually has external script files Total relay-session.test.ts time: 74s → 27s --- playwriter/src/relay-session.test.ts | 33 +++++----------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/playwriter/src/relay-session.test.ts b/playwriter/src/relay-session.test.ts index 8b2dddc..84fb03e 100644 --- a/playwriter/src/relay-session.test.ts +++ b/playwriter/src/relay-session.test.ts @@ -146,15 +146,9 @@ describe('CDP Session Tests', () => { const browserContext = getBrowserContext() const serviceWorker = await getExtensionServiceWorker(browserContext) + // Use a page with actual script URLs (not just inline scripts) const page = await browserContext.newPage() - await page.setContent(` - - - - -

Script Test

- - `) + await page.goto('https://news.ycombinator.com/') await page.bringToFront() await serviceWorker.evaluate(async () => { @@ -163,37 +157,20 @@ describe('CDP Session Tests', () => { await new Promise(r => setTimeout(r, 100)) const browser = await chromium.connectOverCDP(getCdpUrl({ port: TEST_PORT })) - let cdpPage - for (const p of browser.contexts()[0].pages()) { - if (p.isClosed()) { - continue - } - await p.waitForLoadState('domcontentloaded', { timeout: 5000 }).catch(() => {}) - let html = '' - try { - html = await p.content() - } catch { - continue - } - if (html.includes('Script Test')) { - cdpPage = p - break - } - } + const cdpPage = browser.contexts()[0].pages().find(p => p.url().includes('news.ycombinator')) expect(cdpPage).toBeDefined() const wsUrl = getCdpUrl({ port: TEST_PORT }) const cdpSession = await getCDPSessionForPage({ page: cdpPage!, wsUrl }) const dbg = new Debugger({ cdp: cdpSession }) + await dbg.enable() + const scripts = await dbg.listScripts() expect(scripts.length).toBeGreaterThan(0) expect(scripts[0]).toHaveProperty('scriptId') expect(scripts[0]).toHaveProperty('url') - const dataScripts = await dbg.listScripts({ search: 'data:' }) - expect(dataScripts.length).toBeGreaterThan(0) - cdpSession.close() await browser.close() await page.close()