Repository navigation
fix: reject non-2xx and message-only WebDriver HTTP replies and guard non-string screenshots - #531
Open
hoanle0126 wants to merge 2 commits into
Open
hoanle0126 wants to merge 2 commits into
hoanle0126 wants to merge 2 commits into
Conversation
… non-string screenshots (webdriverio#524)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #524
Supersedes #526 (rebased cleanly onto latest
mainafter #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 noerrorfield). Previously:packages/core/src/webdriver-http.tsdid not reject non-2xx status codes andisWebdriverErroronly checkedtypeof value.error === 'string', returning the error object as if it were a base64 screenshot string.captureActionSnapshot,upsertRichestSnapshot, andFrameSnapshotIndexintoimageDocument, whereimageMimecalled.startsWithon the object and aborted the entiretrace.zipexport.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 parsingvalue, reject bodies without avalueproperty, and treatvalueobjects carrying a stringmessagewith no payload keys as errors inisWebdriverError.packages/core/src/action-snapshot.ts: Keepscreenshotonly whenshotis a non-empty string.packages/core/src/screencast.ts: Guard#takeFirstShot, the#startPollinginterval, andpushCdpFrameso 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 emptyscreenshotvalues inFrameSnapshotIndex,imageDocument,buildImageFrameSnapshots,upsertRichestSnapshot,buildSnapshotResources, andsynthesizeSnapshotsFromCommandsso 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 lintnpx tsc --noEmit -p tsconfig.json