From 64dc64c7579e51fa5ff2fad3d9fa65121b83245b Mon Sep 17 00:00:00 2001 From: slayerjain Date: Sat, 14 Nov 2026 02:08:40 +0530 Subject: [PATCH 1/4] fix(playwright): do not wait for a frame's calls once its document goes Settle waited until the test timed out when a page loaded another document while one of its frames (a payment form's iframe) had a call in flight. The frame goes with the old document, and Playwright reports no end for the call: neither for an ordinary call nor for a keepalive one (navigator.sendBeacon, fetch with keepalive), which the browser goes on sending. Settle dropped only the page's own calls then, so a frame's telemetry beacon held each such test until its timeout. A frame's calls are now dropped when Playwright reports the frame detached, as a closed page's calls already are. Rows: a beacon, a keepalive fetch and an ordinary call a frame had in flight when the page loaded another document (each fails with the old settle), and a beacon the frame sends as the page hides, are not waited for; a beacon from a page that stays is still waited for; a unit row drops only the gone frame's call. Signed-off-by: slayerjain --- playwright/README.md | 2 +- playwright/src/settle.ts | 11 ++++- playwright/test/fixtures/settle.spec.ts | 55 +++++++++++++++++++++++++ playwright/test/rows.test.mjs | 50 ++++++++++++++++++++++ playwright/test/unit.test.mjs | 25 +++++++++++ 5 files changed, 140 insertions(+), 3 deletions(-) diff --git a/playwright/README.md b/playwright/README.md index 833cf5f..273fc17 100644 --- a/playwright/README.md +++ b/playwright/README.md @@ -43,7 +43,7 @@ With `KEPLOY_MOCK_AGENT` unset or `off`, nothing changes. Only `keploy mock reco - **Claim.** Each worker claims keploy's run before its first hook or test (`POST /agent/instance`). The claim uses the worker's Playwright project name as its key, or `.` for an unnamed project, and names the project directory keploy names (`KEPLOY_MOCK_PROJECT`) as the folder of its tests, the folder the test files are named from (the current directory only when keploy names none). So a suite run from a folder above its keploy project, such as `cd .. && npx playwright test` in `mock.command`, is filed under its project. A worker that Playwright starts again after a failed test claims again. - **Begin.** Each test begins (`POST /agent/scope/begin`) before its `beforeEach` hooks. keploy builds the test's ID as `[project::]file::titles`. The file is relative to the project directory keploy names (`KEPLOY_MOCK_PROJECT`). The titles are the describe groups and the test's own title, joined with ` › `. - **Skip.** When keploy has set a test aside, the test is skipped through Playwright's own skip, and the report shows keploy's reason (`keploy: ...`). -- **Settle.** Before the test's `context` (and its `page`) closes, the test waits until none of its pages' calls is in flight. Calls are counted by the browser's own request events, and no time window decides. A call that never ends keeps the test waiting until Playwright's test timeout fails it. The test shows a step that names each call still in flight. A call is not waited for once the browser has cancelled it, which happens when its page loads another document, its frame is removed, its page closes or the test closes its own context. A closing page cancels only its own calls: a popup that closes cancels nothing of its opener's. A route change inside the page (the history API) cancels nothing, even after an answered call. A service worker's calls are counted too. No page's change drops them, but the test closing its own context does, as it ends the worker. +- **Settle.** Before the test's `context` (and its `page`) closes, the test waits until none of its pages' calls is in flight. Calls are counted by the browser's own request events, and no time window decides. A call that never ends keeps the test waiting until Playwright's test timeout fails it. The test shows a step that names each call still in flight. A call is not waited for once the browser has cancelled it, which happens when its page loads another document, its frame is removed, its page closes or the test closes its own context. Nor are the calls a page's frames had in flight when the page loaded another document: the frames go with the old document, and Playwright reports no end for their calls, ordinary or keepalive (`navigator.sendBeacon`, `fetch` with `keepalive`, the telemetry a payment form's frame sends, which the browser goes on sending), so waiting for them would hold the test until its timeout. A closing page cancels only its own calls: a popup that closes cancels nothing of its opener's. A route change inside the page (the history API) cancels nothing, even after an answered call. A service worker's calls are counted too. No page's change drops them, but the test closing its own context does, as it ends the worker. - **End.** The test ends (`POST /agent/scope/end`) after its last teardown, with its own outcome. When keploy saw a call with no recorded answer, or a recorded call the test no longer made, the test fails with keploy's text. - **Given values.** `await given(name, value)` tells keploy a value the test made itself. Examples are a session token it signs and a name it stamps with the time. keploy then follows the value wherever the test's calls carry it, as it follows an incoming request's values in a server test. Give a distinctive value, whole, as the calls carry it. `given` must be called inside a test, or in its `beforeEach` or `afterEach` hooks. It returns the value. It needs a keploy whose agent serves `POST /agent/scope/given` (see the limits below). diff --git a/playwright/src/settle.ts b/playwright/src/settle.ts index e353d78..f144342 100644 --- a/playwright/src/settle.ts +++ b/playwright/src/settle.ts @@ -43,9 +43,16 @@ export class Inflight { this.drop((o) => o.frame === f && !o.nav); }); // Nor for the calls of a page that closes. Only that page's calls: a - // popup that closes cancels nothing of its opener. (A removed frame's - // calls the browser does end, as failed requests.) + // popup that closes cancels nothing of its opener. p.on('close', () => this.drop((o) => o.frame !== null && pageOf(o.frame) === p)); + // Nor for the calls of a frame that is gone: removed, or gone with + // the document it was in when the page loaded another (a payment + // form's frame). Playwright reports no end for the calls such a frame + // still had in flight when it went with the page's old document, + // ordinary or keepalive (navigator.sendBeacon, fetch with keepalive, + // which the browser goes on sending). Each frame that goes is + // reported apart, a frame inside it too. + p.on('framedetached', (f) => this.drop((o) => o.frame === f)); }; context.pages().forEach(watch); context.on('page', watch); diff --git a/playwright/test/fixtures/settle.spec.ts b/playwright/test/fixtures/settle.spec.ts index f4237ed..776b4a1 100644 --- a/playwright/test/fixtures/settle.spec.ts +++ b/playwright/test/fixtures/settle.spec.ts @@ -1,3 +1,4 @@ +import type { Frame, Page } from '@playwright/test'; import { test } from '../../dist'; const base = process.env.SLOW_BASE ?? ''; @@ -93,6 +94,60 @@ test('a call its removed cross-site frame had in flight', async ({ page }) => { await page.evaluate(() => { document.getElementById('child')?.remove(); }); await detached; }); +// A frame from another site, loaded and ready (the payment form's frame). +const crossSiteChild = async (page: Page): Promise => { + await page.goto(`${base}/page`); + const attached = page.waitForEvent('frameattached'); + await page.evaluate((src) => new Promise((resolve) => { + const f = document.createElement('iframe'); + f.id = 'child'; + f.onload = () => resolve(); + f.src = src; + document.body.appendChild(f); + }), `${base.replace('//127.0.0.1:', '//localhost:')}/page?child`); + return attached; +}; +// The page loads another document: its frames go with the old one. +const nextDocument = (page: Page) => page.goto(`${base}/page?next`); +test('a beacon its frame sends as the page loads another document', async ({ page }) => { + // Telemetry a frame sends as its page hides (a payment form's). A + // keepalive call outlives its document: the browser still sends it. + const child = await crossSiteChild(page); + await child.evaluate(() => { addEventListener('pagehide', () => { navigator.sendBeacon('/beacon', 'b'); }); }); + await nextDocument(page); + await reached(); +}); +test('a beacon its frame had in flight when the page loads another document', async ({ page }) => { + const child = await crossSiteChild(page); + const sent = page.waitForRequest(/\/beacon$/); + await child.evaluate(() => { navigator.sendBeacon('/beacon', 'b'); }); + await sent; + await reached(); + await nextDocument(page); +}); +test('a keepalive fetch its frame had in flight when the page loads another document', async ({ page }) => { + const child = await crossSiteChild(page); + const sent = page.waitForRequest(/\/beacon$/); + await child.evaluate(() => { void fetch('/beacon', { method: 'POST', body: 'b', keepalive: true }); }); + await sent; + await reached(); + await nextDocument(page); +}); +test('a call its frame had in flight when the page loads another document', async ({ page }) => { + const child = await crossSiteChild(page); + const sent = page.waitForRequest(/\/slow$/); + await child.evaluate(() => { void fetch('/slow'); }); + await sent; + await reached(); + await nextDocument(page); +}); +test('a beacon in flight from the page', async ({ page }) => { + await page.goto(`${base}/page`); + const sent = page.waitForRequest(/\/beacon$/); + await page.evaluate(() => { navigator.sendBeacon('/beacon', 'b'); }); + await sent; + await reached(); +}); test('a call its closed page had in flight', async ({ page, context }) => { await page.goto(`${base}/page`); const other = await context.newPage(); diff --git a/playwright/test/rows.test.mjs b/playwright/test/rows.test.mjs index 8a11dcf..805df39 100644 --- a/playwright/test/rows.test.mjs +++ b/playwright/test/rows.test.mjs @@ -80,6 +80,16 @@ async function pageServer(j) { void released.then(() => res.end('slow')); return; } + // A keepalive call (navigator.sendBeacon, fetch with keepalive): a POST, + // answered as /slow is. + if (req.url === '/beacon' && req.method === 'POST') { + req.resume(); + req.on('end', () => { j.add({ page: 'beacon sent' }); saw(); }); + res.on('close', () => { if (!res.writableFinished) j.add({ page: 'beacon cut' }); }); + res.on('finish', () => j.add({ page: 'beacon answered' })); + void released.then(() => res.end('beacon')); + return; + } res.writeHead(404); res.end(); }); await new Promise((r) => srv.listen(0, '127.0.0.1', r)); @@ -362,6 +372,46 @@ for (const [title, why] of [ }); } +// Settle rows where the page loads another document while one of its +// frames has a call in flight: the frame goes with the old document, and +// Playwright reports no end for its call, ordinary or keepalive +// (navigator.sendBeacon, fetch with keepalive, which the browser still +// sends: the page server sees it). The call is not waited for, so the test +// does not hang until its timeout. +for (const [title, why, call] of [ + ['a beacon its frame sends as the page loads another document', 'its frame sends it as the page loads another document', 'beacon'], + ['a beacon its frame had in flight when the page loads another document', 'the page loads another document, though a beacon outlives its frame', 'beacon'], + ['a keepalive fetch its frame had in flight when the page loads another document', 'the page loads another document, though a keepalive fetch outlives its frame', 'beacon'], + ['a call its frame had in flight when the page loads another document', 'the page loads another document, with an ordinary call of its frame in flight', 'slow'], +]) { + test(`settle: a frame's call is not waited for once ${why}`, async () => { + const j = journal(); + const a = await fakeAgent(j); + const p = await pageServer(j); + try { + const { tests, out } = await playwright(['settle.spec.ts', '-g', title], { ...keployEnv(a.url), SLOW_BASE: p.url, NO_RELEASE: '1', PW_TIMEOUT: '20000' }); + const t = tests[title]; + assert.equal(t.status, 'passed', out); + assert.deepEqual(t.steps.filter((s) => s.startsWith('keploy:')), []); + assert.ok(j.events.some((e) => e.page === `${call} sent`)); + } finally { await p.close(); await a.close(); } + }); +} + +test('settle: a beacon from a page that stays is still waited for', async () => { + const j = journal(); + const a = await fakeAgent(j); + const p = await pageServer(j); + try { + const title = 'a beacon in flight from the page'; + const { tests, out } = await playwright(['settle.spec.ts', '-g', title], { ...keployEnv(a.url), SLOW_BASE: p.url, NO_RELEASE: '1', PW_TIMEOUT: '4000' }); + const t = tests[title]; + assert.equal(t.status, 'timedOut', out); + const named = /^keploy: wait for the test's 1 call\(s\) in flight before its browser context closes: POST http:\/\/127\.0\.0\.1:\d+\/beacon$/; + assert.ok(t.steps.some((s) => named.test(s)), t.steps.join('\n')); + } finally { await p.close(); await a.close(); } +}); + // Settle rows where nothing was cancelled: the call is still waited for, and // the test times out naming it. for (const [title, why, call] of [ diff --git a/playwright/test/unit.test.mjs b/playwright/test/unit.test.mjs index ca3c6d1..cb06645 100644 --- a/playwright/test/unit.test.mjs +++ b/playwright/test/unit.test.mjs @@ -228,6 +228,31 @@ test('settle: a cancel that comes while settle already waits wakes it (its page } }); +test('settle: a frame that is gone drops only its own calls, and wakes settle once none is left', async () => { + // Two frames of one page, each with a call Playwright reports no end for + // once the frame is gone. + const ctx = fakeContext(); + const inflight = new Inflight(ctx); + const page = new EventEmitter(); + ctx.emit('page', page); + const a = { page: () => page }; + const b = { page: () => page }; + const beacon = (frame, url) => ({ frame: () => frame, isNavigationRequest: () => false, method: () => 'POST', url: () => url }); + ctx.emit('request', beacon(a, 'http://localhost/a')); + ctx.emit('request', beacon(b, 'http://localhost/b')); + let settled = false; + inflight.settled().then(() => { settled = true; }); + await ticks(); + page.emit('framedetached', a); + await ticks(); + assert.deepEqual(inflight.describe(), ['POST http://localhost/b'], 'the removed frame\'s call is dropped, the other frame\'s is not'); + assert.equal(settled, false, 'settle still waits for the other frame\'s call'); + page.emit('framedetached', b); + await ticks(); + assert.equal(inflight.size, 0, 'no call is left in flight'); + assert.equal(settled, true, 'settle is woken'); +}); + test('decide: inert, refused, active', () => { const never = () => { throw new Error('runsInside called'); }; assert.deepEqual(decide({}, 10, never), { mode: 'inert' }); From 5c65d0d18e97b3b2b3ac419f932c9e4d6c2920aa Mon Sep 17 00:00:00 2001 From: slayerjain Date: Sat, 14 Nov 2026 04:15:05 +0530 Subject: [PATCH 2/4] test(playwright): let PW_BROWSER pick the browser the rows run in The rows' Playwright project ran only in Chromium, Playwright's default. PW_BROWSER=firefox or webkit now runs them in that browser, so the settle rows can show a frame's calls are dropped when the frame goes in all three browsers. CI's legs still run them in Chromium. Signed-off-by: slayerjain --- playwright/test/fixtures/playwright.config.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/playwright/test/fixtures/playwright.config.ts b/playwright/test/fixtures/playwright.config.ts index bde48ea..45f46a7 100644 --- a/playwright/test/fixtures/playwright.config.ts +++ b/playwright/test/fixtures/playwright.config.ts @@ -9,6 +9,10 @@ export default defineConfig({ reporter: [['json'], ['./steps-reporter.cjs']], outputDir: process.env.PW_OUTPUT_DIR || 'test-results', // PW_UNNAMED=1: one unnamed project, Playwright's default when a config - // lists none. - projects: [{ name: process.env.PW_UNNAMED ? '' : 'p1', use: { headless: true } }], + // lists none. PW_BROWSER=firefox or webkit runs the rows in that browser + // (Chromium, Playwright's default, otherwise). + projects: [{ + name: process.env.PW_UNNAMED ? '' : 'p1', + use: { headless: true, browserName: (process.env.PW_BROWSER || 'chromium') as 'chromium' | 'firefox' | 'webkit' }, + }], }); From 67d72957354c717965f16c51759500f71416ad37 Mon Sep 17 00:00:00 2001 From: slayerjain Date: Sat, 14 Nov 2026 06:26:20 +0530 Subject: [PATCH 3/4] test(playwright): a gone frame's loading document is not waited for A frame whose own document is still loading when the page loads another document goes with the old one, and Playwright reports no end for the frame's document request either. Settle already drops every call of a frame that detaches, its document request included; a row now pins it: a frame from another site commits a document whose last byte the page server holds, then the page loads another document, and the test passes with no wait step. The unit row's gone frame has its document request in flight too. The settle note in the README and settle.ts now say that the browser goes on sending a frame's keepalive call only while the test's context lives: one still in flight when the test ends is cut by the context close, so its answer may not be recorded. Signed-off-by: slayerjain --- playwright/README.md | 2 +- playwright/src/settle.ts | 9 +++++---- playwright/test/fixtures/settle.spec.ts | 9 +++++++++ playwright/test/rows.test.mjs | 6 ++++-- playwright/test/unit.test.mjs | 8 +++++--- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/playwright/README.md b/playwright/README.md index 273fc17..a2b4861 100644 --- a/playwright/README.md +++ b/playwright/README.md @@ -43,7 +43,7 @@ With `KEPLOY_MOCK_AGENT` unset or `off`, nothing changes. Only `keploy mock reco - **Claim.** Each worker claims keploy's run before its first hook or test (`POST /agent/instance`). The claim uses the worker's Playwright project name as its key, or `.` for an unnamed project, and names the project directory keploy names (`KEPLOY_MOCK_PROJECT`) as the folder of its tests, the folder the test files are named from (the current directory only when keploy names none). So a suite run from a folder above its keploy project, such as `cd .. && npx playwright test` in `mock.command`, is filed under its project. A worker that Playwright starts again after a failed test claims again. - **Begin.** Each test begins (`POST /agent/scope/begin`) before its `beforeEach` hooks. keploy builds the test's ID as `[project::]file::titles`. The file is relative to the project directory keploy names (`KEPLOY_MOCK_PROJECT`). The titles are the describe groups and the test's own title, joined with ` › `. - **Skip.** When keploy has set a test aside, the test is skipped through Playwright's own skip, and the report shows keploy's reason (`keploy: ...`). -- **Settle.** Before the test's `context` (and its `page`) closes, the test waits until none of its pages' calls is in flight. Calls are counted by the browser's own request events, and no time window decides. A call that never ends keeps the test waiting until Playwright's test timeout fails it. The test shows a step that names each call still in flight. A call is not waited for once the browser has cancelled it, which happens when its page loads another document, its frame is removed, its page closes or the test closes its own context. Nor are the calls a page's frames had in flight when the page loaded another document: the frames go with the old document, and Playwright reports no end for their calls, ordinary or keepalive (`navigator.sendBeacon`, `fetch` with `keepalive`, the telemetry a payment form's frame sends, which the browser goes on sending), so waiting for them would hold the test until its timeout. A closing page cancels only its own calls: a popup that closes cancels nothing of its opener's. A route change inside the page (the history API) cancels nothing, even after an answered call. A service worker's calls are counted too. No page's change drops them, but the test closing its own context does, as it ends the worker. +- **Settle.** Before the test's `context` (and its `page`) closes, the test waits until none of its pages' calls is in flight. Calls are counted by the browser's own request events, and no time window decides. A call that never ends keeps the test waiting until Playwright's test timeout fails it. The test shows a step that names each call still in flight. A call is not waited for once the browser has cancelled it, which happens when its page loads another document, its frame is removed, its page closes or the test closes its own context. Nor are the calls a page's frames had in flight when the page loaded another document: the frames go with the old document, and Playwright reports no end for their calls, ordinary or keepalive (`navigator.sendBeacon`, `fetch` with `keepalive`, the telemetry a payment form's frame sends, which the browser goes on sending), nor for a frame's own document request still loading, so waiting for them would hold the test until its timeout. The browser goes on sending a keepalive call only while the test's context lives: one still in flight when the test ends is cut by the context close, so its answer may not be recorded. A closing page cancels only its own calls: a popup that closes cancels nothing of its opener's. A route change inside the page (the history API) cancels nothing, even after an answered call. A service worker's calls are counted too. No page's change drops them, but the test closing its own context does, as it ends the worker. - **End.** The test ends (`POST /agent/scope/end`) after its last teardown, with its own outcome. When keploy saw a call with no recorded answer, or a recorded call the test no longer made, the test fails with keploy's text. - **Given values.** `await given(name, value)` tells keploy a value the test made itself. Examples are a session token it signs and a name it stamps with the time. keploy then follows the value wherever the test's calls carry it, as it follows an incoming request's values in a server test. Give a distinctive value, whole, as the calls carry it. `given` must be called inside a test, or in its `beforeEach` or `afterEach` hooks. It returns the value. It needs a keploy whose agent serves `POST /agent/scope/given` (see the limits below). diff --git a/playwright/src/settle.ts b/playwright/src/settle.ts index f144342..8b720f7 100644 --- a/playwright/src/settle.ts +++ b/playwright/src/settle.ts @@ -48,10 +48,11 @@ export class Inflight { // Nor for the calls of a frame that is gone: removed, or gone with // the document it was in when the page loaded another (a payment // form's frame). Playwright reports no end for the calls such a frame - // still had in flight when it went with the page's old document, - // ordinary or keepalive (navigator.sendBeacon, fetch with keepalive, - // which the browser goes on sending). Each frame that goes is - // reported apart, a frame inside it too. + // still had in flight when it went with the page's old document: + // ordinary, keepalive (navigator.sendBeacon, fetch with keepalive, + // which the browser goes on sending only until the test closes its + // context), or the frame's own document request, still loading. Each + // frame that goes is reported apart, a frame inside it too. p.on('framedetached', (f) => this.drop((o) => o.frame === f)); }; context.pages().forEach(watch); diff --git a/playwright/test/fixtures/settle.spec.ts b/playwright/test/fixtures/settle.spec.ts index 776b4a1..cec0ce9 100644 --- a/playwright/test/fixtures/settle.spec.ts +++ b/playwright/test/fixtures/settle.spec.ts @@ -141,6 +141,15 @@ test('a call its frame had in flight when the page loads another document', asyn await reached(); await nextDocument(page); }); +test('a document its frame was still loading when the page loads another document', async ({ page }) => { + // A frame whose own document has not finished loading (a payment form's + // frame, loaded lazily) goes with the page's old document: Playwright + // reports no end for the frame's own navigation request either. The + // frame commits /slowdoc, whose last byte the page server holds. + const child = await crossSiteChild(page); + await child.goto(`${base.replace('//127.0.0.1:', '//localhost:')}/slowdoc`, { waitUntil: 'commit' }); + await nextDocument(page); +}); test('a beacon in flight from the page', async ({ page }) => { await page.goto(`${base}/page`); const sent = page.waitForRequest(/\/beacon$/); diff --git a/playwright/test/rows.test.mjs b/playwright/test/rows.test.mjs index 805df39..0421c59 100644 --- a/playwright/test/rows.test.mjs +++ b/playwright/test/rows.test.mjs @@ -376,13 +376,15 @@ for (const [title, why] of [ // frames has a call in flight: the frame goes with the old document, and // Playwright reports no end for its call, ordinary or keepalive // (navigator.sendBeacon, fetch with keepalive, which the browser still -// sends: the page server sees it). The call is not waited for, so the test -// does not hang until its timeout. +// sends: the page server sees it), nor for the frame's own document request +// when that document was still loading. The call is not waited for, so the +// test does not hang until its timeout. for (const [title, why, call] of [ ['a beacon its frame sends as the page loads another document', 'its frame sends it as the page loads another document', 'beacon'], ['a beacon its frame had in flight when the page loads another document', 'the page loads another document, though a beacon outlives its frame', 'beacon'], ['a keepalive fetch its frame had in flight when the page loads another document', 'the page loads another document, though a keepalive fetch outlives its frame', 'beacon'], ['a call its frame had in flight when the page loads another document', 'the page loads another document, with an ordinary call of its frame in flight', 'slow'], + ['a document its frame was still loading when the page loads another document', 'the page loads another document while the frame\'s own document is still loading', 'slowdoc'], ]) { test(`settle: a frame's call is not waited for once ${why}`, async () => { const j = journal(); diff --git a/playwright/test/unit.test.mjs b/playwright/test/unit.test.mjs index cb06645..2840154 100644 --- a/playwright/test/unit.test.mjs +++ b/playwright/test/unit.test.mjs @@ -228,9 +228,9 @@ test('settle: a cancel that comes while settle already waits wakes it (its page } }); -test('settle: a frame that is gone drops only its own calls, and wakes settle once none is left', async () => { +test('settle: a frame that is gone drops only its own calls, its own document request too, and wakes settle once none is left', async () => { // Two frames of one page, each with a call Playwright reports no end for - // once the frame is gone. + // once the frame is gone. The first frame's own document is still loading. const ctx = fakeContext(); const inflight = new Inflight(ctx); const page = new EventEmitter(); @@ -238,6 +238,8 @@ test('settle: a frame that is gone drops only its own calls, and wakes settle on const a = { page: () => page }; const b = { page: () => page }; const beacon = (frame, url) => ({ frame: () => frame, isNavigationRequest: () => false, method: () => 'POST', url: () => url }); + const doc = (frame, url) => ({ frame: () => frame, isNavigationRequest: () => true, method: () => 'GET', url: () => url }); + ctx.emit('request', doc(a, 'http://localhost/slowdoc')); ctx.emit('request', beacon(a, 'http://localhost/a')); ctx.emit('request', beacon(b, 'http://localhost/b')); let settled = false; @@ -245,7 +247,7 @@ test('settle: a frame that is gone drops only its own calls, and wakes settle on await ticks(); page.emit('framedetached', a); await ticks(); - assert.deepEqual(inflight.describe(), ['POST http://localhost/b'], 'the removed frame\'s call is dropped, the other frame\'s is not'); + assert.deepEqual(inflight.describe(), ['POST http://localhost/b'], 'the gone frame\'s calls are dropped, its document request too; the other frame\'s is not'); assert.equal(settled, false, 'settle still waits for the other frame\'s call'); page.emit('framedetached', b); await ticks(); From 25932cd37acb3df268457a91bd2473826e3011da Mon Sep 17 00:00:00 2001 From: slayerjain Date: Sat, 14 Nov 2026 07:20:17 +0530 Subject: [PATCH 4/4] test(playwright): a gone frame leaves the other frame's document counted The unit row for a frame that is gone gave the other frame only a beacon, so it did not pin that settle keeps counting another frame's document request while it loads. Give that frame a document request too, and expect it still named after the first frame goes. Signed-off-by: slayerjain --- playwright/test/unit.test.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/playwright/test/unit.test.mjs b/playwright/test/unit.test.mjs index 2840154..2265e0c 100644 --- a/playwright/test/unit.test.mjs +++ b/playwright/test/unit.test.mjs @@ -230,7 +230,7 @@ test('settle: a cancel that comes while settle already waits wakes it (its page test('settle: a frame that is gone drops only its own calls, its own document request too, and wakes settle once none is left', async () => { // Two frames of one page, each with a call Playwright reports no end for - // once the frame is gone. The first frame's own document is still loading. + // once the frame is gone, and each with its own document still loading. const ctx = fakeContext(); const inflight = new Inflight(ctx); const page = new EventEmitter(); @@ -241,14 +241,15 @@ test('settle: a frame that is gone drops only its own calls, its own document re const doc = (frame, url) => ({ frame: () => frame, isNavigationRequest: () => true, method: () => 'GET', url: () => url }); ctx.emit('request', doc(a, 'http://localhost/slowdoc')); ctx.emit('request', beacon(a, 'http://localhost/a')); + ctx.emit('request', doc(b, 'http://localhost/bdoc')); ctx.emit('request', beacon(b, 'http://localhost/b')); let settled = false; inflight.settled().then(() => { settled = true; }); await ticks(); page.emit('framedetached', a); await ticks(); - assert.deepEqual(inflight.describe(), ['POST http://localhost/b'], 'the gone frame\'s calls are dropped, its document request too; the other frame\'s is not'); - assert.equal(settled, false, 'settle still waits for the other frame\'s call'); + assert.deepEqual(inflight.describe(), ['GET http://localhost/bdoc', 'POST http://localhost/b'], 'the gone frame\'s calls are dropped, its document request too; the other frame\'s call and document request are not'); + assert.equal(settled, false, 'settle still waits for the other frame\'s calls'); page.emit('framedetached', b); await ticks(); assert.equal(inflight.size, 0, 'no call is left in flight');