diff --git a/tests/webview/webviewTest.ts b/tests/webview/webviewTest.ts index b5e0e1c21d939..f5896b7250174 100644 --- a/tests/webview/webviewTest.ts +++ b/tests/webview/webviewTest.ts @@ -18,11 +18,14 @@ import { spawnSync } from 'child_process'; import fs from 'fs'; import path from 'path'; +import { iso } from '../../packages/playwright-core/lib/coreBundle'; import { baseTest } from '../config/baseTest'; import { loadWebViewExpectations, shouldSkipWebViewTest, type WebViewExpectation } from './expectationUtil'; import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi'; export { expect } from '@playwright/test'; +const { raceAgainstDeadline } = iso; + const PROXY_BASE = process.env.PW_WEBVIEW_PROXY_BASE || 'http://localhost:9222'; type WebViewWorkerFixtures = PageWorkerFixtures & { @@ -138,7 +141,7 @@ export const webviewTest = baseTest.extend { + page: async ({ playwright, webviewEndpoint }, run, testInfo) => { const browser = await playwright.webkit.connectOverCDP(webviewEndpoint); const [context] = browser.contexts(); const pages = context.pages(); @@ -148,9 +151,12 @@ export const webviewTest = baseTest.extend {}); await run(page); - // The shared Mobile Safari cookie store persists across tests; clear it - // while still on the test's domain (webview cookies are domain-scoped). - await page.context().clearCookies().catch(() => {}); + // The shared Mobile Safari cookie store persists across tests; clear it while + // still on the test's domain (webview cookies are domain-scoped). A test that + // wedges the page's main thread stalls the inspector protocol, so cap this at + // the remaining test timeout, reserving a moment for `browser.close()` below. + const { deadline } = (testInfo as unknown as { _deadline(): { deadline: number } })._deadline(); + await raceAgainstDeadline(() => page.context().clearCookies().catch(() => {}), deadline - 250); await browser.close(); },