new Index(_webSocketUrl)
Create a new websocket connection
| Name | Type | Description |
|---|---|---|
_webSocketUrl |
- Source
Members
isConnected
- Source
socket
- Source
status
Get Bidi Status
- Source
Methods
(async) addCallback(method, handler) → {Promise.<{id: string, unsubscribe: function(): Promise.<void>}>}
Registers handler to be called on every delivered method event, globally (no context/user-context scoping). This is the correct mechanism — see the note on subscribe/unsubscribe above, which is a separate, imprecise, event-name-scoped mechanism kept only for the existing hand-written bidi/*.js modules until they're replaced by generated code built on this method instead.
Keyed by the server-assigned subscription id from session.subscribe's response, which the spec mints fresh on every call — so multiple independent subscriptions to the same event coexist safely, and the returned handle's unsubscribe() never affects another callback registered for the same method. No client-side ref-counting is needed: the protocol's own per-subscription id already gives each caller its own independent, individually-cancellable registration.
The local listener is attached before session.subscribe is awaited, not after — so an event the browser starts sending as soon as it processes the subscription can't arrive in a gap where nothing is listening yet. If the subscribe call then fails (or returns no usable id), the listener is removed again before the error propagates, so a failed subscription doesn't leak one.
| Name | Type | Description |
|---|---|---|
method | string | |
handler | function |
- Source
- Type:
- Promise.<{id: string, unsubscribe: function(): Promise.<void>}>
close() → {Promise.<unknown>}
Close ws connection.
- Source
- Type:
- Promise.<unknown>
(async) removeCallback(subscriptionId) → {Promise.<void>}
Removes exactly the callback registered under subscriptionId (as returned by addCallback). A no-op if already removed — including once the connection is closed, since _failPending() has already cleaned up local state at that point (and there is no remote end left to reach: entry is only ever defined here while _closed is still false, since _failPending() clears every entry in the same synchronous call that sets _closed). Never affects any other callback, including another one registered for the same method.
Local state is only cleaned up once the remote end has confirmed the subscription is actually gone — not before sending session.unsubscribe, and not on a wire-level error response. Cleaning up first would leave a phantom "removed" subscription if the send failed or was rejected: local delivery would stop while the browser kept sending it, and a retry would silently no-op since this method's own early return above would find no entry left to act on.
Concurrent calls for the same subscriptionId share one in-flight removal instead of each sending their own session.unsubscribe — a second, racing call would otherwise find the subscription already gone (removed by the first) and get a wire-level error for what was a perfectly valid call. The in-flight marker is cleared once the attempt settles, either way, so a later retry after a failure starts a fresh attempt rather than reusing a rejected one.
| Name | Type | Description |
|---|---|---|
subscriptionId | string |
- Source
- Type:
- Promise.<void>
(async) send(params) → {Promise.<unknown>}
Sends a bidi request
| Name | Type | Description |
|---|---|---|
params |
- Source
- Type:
- Promise.<unknown>
(async) subscribe(events, browsingContexts) → {Promise.<void>}
Subscribe to events.
Not the correct implementation — this is not tied to a subscription id, so unsubscribe below cancels by event/context name and can affect a subscription made elsewhere (including via addCallback) for the same event. Kept as-is only because the existing hand-written bidi/*.js modules already depend on this exact shape; new code should use addCallback instead, which is properly scoped by subscription id (mirroring Java's BiDi#addListener/removeListener — see BiDi.java). Once those hand-written modules are replaced by generated code built on addCallback/removeCallback, this method (and unsubscribe) can be removed.
| Name | Type | Description |
|---|---|---|
events | ||
browsingContexts |
- Source
- Type:
- Promise.<void>
(async) unsubscribe(events, browsingContexts) → {Promise.<void>}
Unsubscribe to events. See the note on subscribe above — this cancels by event/context name, not by subscription id, so it can affect a subscription this same connection made elsewhere. New code should call the returned handle's unsubscribe() from addCallback instead.
| Name | Type | Description |
|---|---|---|
events | ||
browsingContexts |
- Source
- Type:
- Promise.<void>
(async) waitForConnection() → {Promise.<unknown>}
Resolve connection
- Source
- Type:
- Promise.<unknown>