Skip to content

fix(browser-pay): report why an intercept arm failed - #1262

Merged
ratataque merged 9 commits into
mainfrom
cursor/intercept-unavailable-diagnostics-d715
Oct 27, 2026
Merged

ratataque merged 9 commits into
mainfrom
cursor/intercept-unavailable-diagnostics-d715

Conversation

@ratataque

@ratataque ratataque commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Bug fix
  • Documentation
  • Feature
  • Tests
  • Dependency update
  • Maintenance or refactor

Problem and motivation

When arming a target fails, the caller only saw failed with reason intercept_unavailable and the target closed. The public event stays that shape. An optional logger can now record which browser step failed, without the browser's error text.

Summary and scope

  • InterceptorEvent is unchanged. intercept_unavailable is still { type: "failed", url, reason: "intercept_unavailable" }, and the target is still closed with Target.closeTarget.
  • An optional logger receives browser step failed for a Fetch.enable arm failure and for swallowed nested Target.setAutoAttach, Runtime.runIfWaitingForDebugger, Target.getTargets, Target.attachToTarget, and Target.closeTarget. Fields are the local method, an integer code when the browser sent one, timedOut, and targetType / origin-only origin when known. The default logger is silent. A throwing logger does not change control flow.
  • CdpCommandError names a plain Domain.method (CDP command failed: Target.setAutoAttach). Any other method string keeps the generic message and leaves method undefined. Remote error text is not included.
  • Network.enable, Target.setDiscoverTargets, Fetch.disable, and detach-time sends stay silent. No new events, states, or close paths.

Related work

Related issue or discussion: N/A

Validation

pnpm --filter @sapiom/browser-pay typecheck — pass (exit 0)
pnpm --filter @sapiom/browser-pay lint — pass (exit 0)
pnpm --filter @sapiom/browser-pay exec jest — pass
  Test Suites: 7 passed, 7 total
  Tests:       86 passed, 86 total
  Time:        10.325 s

Compatibility and release impact

  • Breaking or externally visible changes: the public event type is unchanged. CdpCommandError messages name a plain CDP method. PayLogger field values may be boolean (timedOut). Fail-closed close behaviour is unchanged.
  • Changeset: Added. @sapiom/browser-pay patch.

Security

  • I have not included secrets, credentials, private data, or unsanitized logs.
  • This pull request does not publicly disclose a suspected vulnerability. I
    will follow the
    Security Policy for
    private reporting.

Logs and errors do not include card data, request bodies, headers, a URL beyond origin, or the browser's error text. A method name is included only when it is a plain Domain.method.

Decision for Ewan

Log-only. The public event is not extended. Opt-in debug flag exposing raw CDP error text: no.

AI assistance

  • I did not use AI assistance for this change.
  • I used AI assistance and have described it below.

A Cursor cloud agent wrote the change. It was checked with the package typecheck, lint, and Jest suite.

Checklist

  • I read CONTRIBUTING.md, and this contribution follows the direct-PR or issue-first policy.
  • This pull request addresses one focused problem and contains no unrelated cleanup.
  • I added or updated tests, or explained above why tests are not applicable.
  • I ran the relevant build, typecheck, lint, and test commands, or explained
    any N/A checks above.
  • I updated documentation for user-facing changes, or marked it N/A above.
  • I added a Changeset for a published-package change, or explained why it is not applicable.
  • I can explain and maintain every submitted change, including any AI-assisted work.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features
    • Optional logging now reports failures in browser setup and target-handling steps, with structured details such as the failed CDP method, timeout status, and sanitized target information.
    • CDP command errors now identify the method and may include a valid error code, without exposing browser-provided error text.
  • Bug Fixes
    • CDP command timeouts and failed responses now provide consistent, structured errors, making failures easier to identify.
    • Logging failures no longer interrupt browser-step error handling.

Callers only saw intercept_unavailable when a target could not be armed.
The failed event now carries the CDP method, numeric code, timeout flag,
target type, and origin. closeTarget still runs. Remote error text is
not included.

A nested setAutoAttach failure, and an attachToTarget failure on an
iframe that would have been armed, now close that target too. Captcha,
extension, and worker targets stay open.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34060e71-cd99-4cde-809d-4600cfc840ab
Commits

Reviewing files that changed from the base of the PR and between 9a9f379 and 0fe2042.

Files selected for processing: 2
  • packages/browser-pay/src/interceptor.protocol.test.ts
  • packages/browser-pay/src/interceptor.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The browser-pay package adds structured CDP command errors with method names and optional integer codes. The interceptor can log selected browser-step failures with sanitized target details. Tests cover error handling, logging, and logger exceptions.

Changes: Browser Pay Diagnostics

Layer / File(s) Summary
Structured CDP errors
packages/browser-pay/src/cdp.ts, packages/browser-pay/src/cdp.test.ts, packages/browser-pay/src/interceptor.event-redaction.test.ts, packages/browser-pay/src/interceptor.protocol.test.ts
CDP command failures and timeouts now use CdpCommandError. The error includes a valid method name and optional integer code, and omits remote error text. Tests check timeout details and error-property redaction.
Browser-step failure logging
packages/browser-pay/src/interceptor.ts, packages/browser-pay/src/logger.ts, packages/browser-pay/src/interceptor.protocol.test.ts, packages/browser-pay/README.md, .changeset/browser-pay-intercept-diagnostics.md
The interceptor logs selected CDP step failures with structured fields and sanitized origins. Logger exceptions are suppressed. Tests cover these paths, and the README and changeset describe the diagnostics.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Interceptor
  participant CDPConnection
  participant PayLogger
  Interceptor->>CDPConnection: Send Fetch.enable
  CDPConnection-->>Interceptor: Reject with CdpCommandError
  Interceptor->>PayLogger: Log failure details
  Interceptor->>CDPConnection: Send Target.closeTarget
Loading

Suggested reviewers: antoine-berger

Merge Risk: Minimal · up to 0fe20

The reported logging failure appears contained at the reviewed head, with no identified issue preventing merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reporting why browser interception arming failed.
Description check Passed The description is complete and follows the repository template. It explains the problem, scope, related work, validation results, compatibility impact, security considerations, AI assistance, and che…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and follows the repository template. It explains the problem, scope, related work, validation results, compatibility impact, security considerations, AI assistance, and checklist status.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the method name,
And keeps the remote text out of frame.
A warning carries codes that pass,
While logger faults leave flow intact.
Fetch failures close the target’s door,
Then quiet ears hop off once more.

Comment @coderabbitai help to get the list of available commands.

cursoragent and others added 5 commits October 26, 2026 21:25
The failed event reports only the CDP methods armFetch can fail on,
plus the integer code, timeout flag, target type, and origin.
closeTarget is unchanged. Nested attach failures stay swallowed.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
Network.enable is swallowed, so the event only names Fetch.enable. Cover a short command timeout and a non-integer CDP code that omits code.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
CdpCommandError includes the local method. Nested auto-attach, resume, existing-frame attach, and close log through the existing logger without changing control flow.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
The catch only runs after Network.enable is swallowed, so the method is always Fetch.enable.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
A consumer logger must not reject arming or skip detach. The logged method is the literal the caller passed.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>

Copy link
Copy Markdown
Contributor Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

cursoragent and others added 2 commits October 26, 2026 23:52
Only a plain Domain.method is named. Any other caller-supplied method keeps the generic failure and timeout messages.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>
intercept_unavailable is the same event as before. An optional logger records why Fetch.enable failed, alongside the other swallowed steps.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>

Copy link
Copy Markdown
Contributor Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

@ratataque
ratataque marked this pull request as ready for review October 27, 2026 00:41
Copilot AI balanced review requested due to automatic review settings October 27, 2026 00:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused diagnostics preserve existing failure behavior and redaction boundaries, with regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Adds optional, sanitized diagnostics to browser-pay so callers can identify failed browser steps without changing public events or fail-closed behavior.

Changes:

  • Logs selected browser-step failures with method, timeout status, integer error code, and sanitized target context.
  • Adds structured CDP errors that name valid methods while excluding remote error text.
  • Expands regression tests and documents the diagnostics in a patch changeset.
File Description
packages/​browser-pay/​src/​logger.ts Allows boolean log fields for timeout status.
packages/​browser-pay/​src/​interceptor.ts Logs selected failures without changing interception control flow.
packages/​browser-pay/​src/​interceptor.protocol.test.ts Tests diagnostics, redaction, and throwing-logger behavior.
packages/​browser-pay/​src/​interceptor.event-redaction.test.ts Verifies safe error messages and unchanged event shapes.
packages/​browser-pay/​src/​cdp.ts Adds sanitized command errors with method and failure metadata.
packages/​browser-pay/​src/​cdp.test.ts Tests structured timeout errors.
packages/​browser-pay/​README.md Documents optional logging and method-aware errors.
.changeset/​browser-pay-intercept-diagnostics.md Records a browser-pay patch release.

Review effort: Balanced

@GrimalDev

GrimalDev commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

interceptor.ts:461: async logger rejection escapes the guard and crashes Node; reproduced against head, while base exits normally.

Co-authored-by: Rimmely Ewan <ratataque@users.noreply.github.com>

@GrimalDev GrimalDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ratataque
ratataque merged commit 150bbd7 into main Oct 27, 2026
11 checks passed
@ratataque
ratataque deleted the cursor/intercept-unavailable-diagnostics-d715 branch October 27, 2026 17:11
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.

4 participants