From 2833926e79ea81c4e370fc51a3428016ec6970c0 Mon Sep 17 00:00:00 2001 From: Devin Rousso Date: Mon, 22 Jun 2026 17:29:30 -0600 Subject: [PATCH] test(webview): add a timeout for `clearCookies` in teardown so a busy page can't stall it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as part of the test teardown we attempt to clear all cookies this is done via multiple round-trips using the WebKit inspector protocol (`Page.getCookies` and then `Page.deleteCookie` for each) `tests/page/page-set-content.spec.ts:153:3 › should handle timeout properly` will infinitely loop the page as a result, none of the WebKit inspector protocol messages are handled, meaning we will timeout trying to teardown the test add a timeout limit for clearing cookies so that if it fails it doesn't cause the test to fail --- tests/webview/webviewTest.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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(); },