Skip to content

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

Open
hoanle0126 wants to merge 2 commits into
webdriverio:mainfrom
hoanle0126:fix/screenshot-after-session-end-524
Open

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

Conversation

@hoanle0126

Copy link
Copy Markdown
Contributor

Closes #524
Supersedes #526 (rebased cleanly onto latest main after #522/#527).

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

This branch has not been deployed

No deployments
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