Skip to content

fix(playwright): do not wait for a frame's calls once its document goes - #126

Merged
slayerjain merged 4 commits into
mainfrom
fix/playwright-settle-frame-next
Nov 14, 2026
Merged

slayerjain merged 4 commits into
mainfrom
fix/playwright-settle-frame-next

Conversation

@slayerjain

Copy link
Copy Markdown
Member

What was wrong

Before a test's browser context closes, @keploy/playwright waits until none of the test's calls is in flight (settle). It counts calls by Playwright's own request events, and drops a call once the browser cancels it: when its page loads another document, its page closes, or the test closes its context.

When a page loads another document, the frames of the old document (a payment form's iframe) go with it. Playwright reports no end for the calls those frames still had in flight: neither for an ordinary call nor for a keepalive one (navigator.sendBeacon, fetch with keepalive: true), which the browser goes on sending, nor for a frame's own document request while that document is still loading. Settle dropped only the page's own calls at that moment, so it went on counting the frame's call and held the test until Playwright's test timeout.

Seen in enterprise-ui's Playwright suite under keploy mock record: as the app loads another page, Stripe.js's controller frame posts two telemetry beacons to https://r.stripe.com/b (resource type ping) 20 ms before the frame goes with the old document. Every call settle still counted at the end of each hung test was such a beacon, and those tests waited two minutes, until their timeout.

What changes

  • src/settle.ts: when Playwright reports a frame detached, the calls of that frame still counted are dropped, its own document request included, as a closed page's calls already are. Playwright reports each frame that goes, a frame inside it too.
  • A removed frame's calls Playwright already reports as failed (net::ERR_ABORTED), beacons included, so for a frame the page removes nothing changes.
  • A beacon from a page that stays is still waited for.
  • The browser goes on sending a frame's keepalive call only while the test's context lives. Settle no longer waits for it, so when it is still in flight as the test ends, the context close cuts it, and its answer may not be recorded.
  • README: the settle note names the calls of a page's frames when the page loads another document, and says that a keepalive call still in flight when the test ends is cut by the context close.

Tests

  • test/rows.test.mjs with test/fixtures/settle.spec.ts (real Chromium runs against the fake agent and a page server that holds /beacon, /slow and the last byte of /slowdoc until the row lets them go):
    • a beacon, a keepalive fetch and an ordinary fetch a frame from another site had in flight when the page loaded another document: each test passes with no wait step, and the page server received the call; with the old settle.ts each of the three times out;
    • a beacon the frame sends from its pagehide handler as the page loads another document: not waited for;
    • a frame from another site whose own document (/slowdoc, its last byte held) is still loading when the page loads another document: the test passes with no wait step; with the old settle.ts, or with the frame's document request kept counted, it fails: settle still counts GET .../slowdoc, whose last byte never comes;
    • a beacon from the page itself, never answered: still waited for; the test times out with the step naming POST .../beacon.
  • test/unit.test.mjs: with calls in two frames of a page, each frame's own document request among them, the first frame going drops only its calls, its document request too (the other frame's call and its own document request are still named), and settle keeps waiting; the second going wakes it.
  • test/fixtures/playwright.config.ts: PW_BROWSER=firefox or webkit runs the rows in that browser; CI's legs (Node 20, 22 and 24) run them in Chromium, the browser the workflow installs.

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 <shubhamkjain@outlook.com>
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 <shubhamkjain@outlook.com>
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 <shubhamkjain@outlook.com>
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 <shubhamkjain@outlook.com>
@slayerjain
slayerjain merged commit ba8e956 into main Nov 14, 2026
8 checks passed
@slayerjain
slayerjain deleted the fix/playwright-settle-frame-next branch November 14, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant