Repository navigation
Closed
Description
Summary
A Nightwatch run in trace mode against BrowserStack (iOS native, XCUITest) sometimes writes no trace zip at all. The test passes, and the log shows:
WARN @wdio/nightwatch-devtools: trace write failed: base64.startsWith is not a function
The whole session's trace is lost, not one row. Reproduced on main (b9791e5) and on the #442 branch: 1 of 4 runs on main, 2 of 5 on the branch, with the same mechanism. #442 does not introduce it.
Cause
- The last action fires several screenshot requests at once: the row's screenshot, the per-action snapshot and the screencast poller. The device serves them one at a time, about 0.5 s each.
- Nightwatch deletes the session about 1 s after the last command. A screenshot request that reaches the hub after the DELETE is answered with HTTP 404 and the message
Session not started or terminated, with noerrorfield. packages/core/src/webdriver-http.tsisWebdriverErroronly treats a payload as an error whenvalue.erroris a string. This reply has noerrorfield, sowebdriverGet<string>(browser, 'screenshot')returns the object as if it were the screenshot.- The object travels through
packages/nightwatch-devtools/src/action-snapshot.ts, core'scaptureActionSnapshot(screenshot: shot ?? undefined) andupsertRichestSnapshotintoActionSnapshot.screenshot. packages/trace/src/trace-frame-snapshots.tsimageDocumentguards onlynull/undefined(snap.screenshot ?? ''), sopackages/shared/src/image.tsimageMimecalls.startsWithon an object and throws.trace-finalizer.tscatches it astrace write failed, and no zip is written.
The error-shape check came in with 772ff82.
Evidence
- Probe logs that record every
/screenshotresponse with its HTTP status andtypeof. In a failing run on main, the three requests started within 4 ms of each other and ended +658/+1012/+1282 ms later. The last one washttp=404 typeof=object. - In another run, the same object also reached the screencast poller. That run's trace was saved, so the poller survived it, but how the poller handles a non-string frame was not checked.
- Every successful response was a base64 PNG string (320-760 KB).
Scope
Seen with Nightwatch on a BrowserStack iOS native session. Any adapter that probes a screenshot over raw WebDriver HTTP while the session is being deleted can hit it, when the grid answers with a body that has no error field. Local chromedriver answers {value: {error: ...}}, which is already filtered, so this is mostly a cloud-grid issue.
Proposed fix
core/webdriver-http.ts: reject a non-2xx response before parsing it as a value. Treat a body withoutvalue, or avaluewith a stringmessageand no payload, as an error.- Defence in depth where the value is consumed:
captureActionSnapshot(core) keepsscreenshotonly when it is a non-empty string, andimageDocument/FrameSnapshotIndexskip a non-string screenshot. One bad frame should cost a frame, never the whole zip. - Check how the screencast poller handles a non-string frame in the same change.
Tests
webdriverGetagainst a fake 404{"message": ...}response rejects, or returns null like the existing error path.- A trace export with one snapshot whose
screenshotis an object still writes a zip, and that row resolves to the previous frame.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix: reject non-2xx and message-only WebDriver HTTP replies and guard…
fix: reject non-2xx and message-only WebDriver HTTP replies and guard…
fix: reject non-2xx and message-only WebDriver HTTP replies and guard…