Skip to content

CDP HTTP endpoint discovery omits configured authentication headers #3525

Open

Description

@soarkit

CDP HTTP endpoint discovery omits configured authentication headers

Summary

For an HTTP CDP endpoint, resolveWebSocketEndpoint fetches /json/version without the configured headers, while the later WebSocket constructor does receive them. An authenticated endpoint therefore rejects discovery before the connection can be opened.

Location

  • Repository: browserbase/stagehand
  • File: packages/evals/core/tools/cdp_code.ts
  • Line: 129 (resolveWebSocketEndpoint; header forwarding at 197–208)
  • Revision: 0336409092b8

Affected code

async function resolveWebSocketEndpoint(input: {
  kind: "ws" | "http";
  url: string;
}): Promise<string> {
  if (input.kind === "ws") {
    return input.url;
  }

  const baseUrl = input.url.replace(/\/$/, "");
  const response = await fetch(`${baseUrl}/json/version`);
  ...
}

The call has no headers argument, although the input type later carries:

headers?: Record<string, string>;

and the WebSocket is constructed with:

new WebSocket(wsUrl, input.headers ? { headers: input.headers } : {});

Expected behavior

With an HTTP CDP endpoint that requires:

Authorization: Bearer secret

discovery of /json/version must send the configured headers, so the endpoint returns the JSON payload with webSocketDebuggerUrl.

Actual behavior

Against a local CDP HTTP endpoint requiring Authorization: Bearer secret, calling the real resolveWebSocketEndpoint:

error=Failed to resolve CDP websocket URL from http://127.0.0.1:18991: 401 Unauthorized

The endpoint rejects discovery with 401 before the configured headers ever reach it.

The current default branch still has:

const response = await fetch(`${baseUrl}/json/version`);

with no headers.

Root cause

Headers are passed only to the WebSocket constructor (new WebSocket(wsUrl, { headers })). The required HTTP discovery request uses bare fetch, so authenticated endpoints cannot resolve.

Suggested fix

Thread the configured headers into the discovery request:

const response = await fetch(`${baseUrl}/json/version`, {
  headers: input.headers,
});

and include headers in the resolveWebSocketEndpoint input type. Add a test with an HTTP endpoint that returns 401 without the authorization header.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions