Skip to content

fix: reject non-2xx and message-only WebDriver HTTP replies and guard non-string screenshots - #526

Closed
hoanle0126 wants to merge 1 commit into
webdriverio:mainfrom
hoanle0126:fix/screenshot-after-session-end-524
Closed

hoanle0126 wants to merge 1 commit into
webdriverio:mainfrom
hoanle0126:fix/screenshot-after-session-end-524

Conversation

@hoanle0126

Copy link
Copy Markdown
Contributor

Closes #524

Summary

When a screenshot probe reaches a cloud grid after the session has already ended, the hub can respond with HTTP 404 and a JSON body such as {"value": {"message": "Session not started or terminated"}} (or {"message": "..."} with no error field). Previously:

  1. packages/core/src/webdriver-http.ts did not reject non-2xx status codes and isWebdriverError only checked typeof value.error === 'string', returning the error object as if it were a base64 screenshot string.
  2. That object flowed through captureActionSnapshot, upsertRichestSnapshot, and FrameSnapshotIndex into imageDocument, where imageMime called .startsWith on the object and aborted the entire trace.zip export.

This PR implements both the transport fix and defence-in-depth guards across snapshot capture, screencast polling, and trace export:

  • packages/core/src/webdriver-http.ts: Reject non-2xx HTTP responses before parsing value, reject bodies without a value property, and treat value objects carrying a string message with no payload keys as errors in isWebdriverError.
  • packages/core/src/action-snapshot.ts: Keep screenshot only when shot is a non-empty string.
  • packages/core/src/screencast.ts: Guard #takeFirstShot, the #startPolling interval, and pushCdpFrame so only non-empty strings are appended to the frame buffer.
  • packages/trace/src/trace-frame-snapshots.ts, trace-snapshots.ts, trace-exporter.ts: Skip non-string or empty screenshot values in FrameSnapshotIndex, imageDocument, buildImageFrameSnapshots, upsertRichestSnapshot, buildSnapshotResources, and synthesizeSnapshotsFromCommands so a malformed frame falls back to the preceding valid frame rather than failing the zip export.

Verification

  • npx vitest run packages/core/tests/webdriver-http.test.ts packages/core/tests/action-snapshot.test.ts packages/core/tests/screencast.test.ts packages/trace/tests/trace-frame-snapshots.test.ts packages/trace/tests/trace-exporter.test.ts packages/trace/tests/trace-snapshots.test.ts (119 passed)
  • pnpm --filter @wdio/devtools-core --filter @wdio/devtools-trace lint
  • npx tsc --noEmit -p tsconfig.json

@hoanle0126
hoanle0126 force-pushed the fix/screenshot-after-session-end-524 branch from 7a8088b to aaaf076 Compare November 3, 2026 03:23
@hoanle0126 hoanle0126 closed this Nov 3, 2026
@hoanle0126
hoanle0126 force-pushed the fix/screenshot-after-session-end-524 branch from aaaf076 to 8f2c779 Compare November 3, 2026 03:31
@hoanle0126

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main in #531 (GitHub auto-closed this PR during the force-push rebase and locked reopening).

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.

Nightwatch on a cloud grid can lose the whole trace when a screenshot lands after the session ended

1 participant