Skip to main content

Module: browser

Tools for accessing Convex in the browser.

If you are using React, use the react module instead.

Usage

Create a ConvexHttpClient to connect to the Convex Cloud.

import { ConvexHttpClient } from "convex/browser";
// typically loaded from an environment variable
const address = "https://small-mouse-123.convex.cloud";
const convex = new ConvexHttpClient(address);

Classes

Interfaces

Type Aliases

ConvexClientOptions

Ƭ ConvexClientOptions: BaseConvexClientOptions & { disabled?: boolean ; unsavedChangesWarning?: boolean }

Defined in

browser/simple_client.ts:28


AuthTokenFetcher

Ƭ AuthTokenFetcher: (args: { forceRefreshToken: boolean }) => Promise<string | null | undefined>

Type declaration

▸ (args): Promise<string | null | undefined>

An async function returning a JWT. Depending on the auth providers configured in convex/auth.config.ts, this may be a JWT-encoded OpenID Connect Identity Token or a traditional JWT.

forceRefreshToken is true if the server rejected a previously returned token or the token is anticipated to expiring soon based on its exp time.

See ConvexReactClient.setAuth.

Parameters
NameType
argsObject
args.forceRefreshTokenboolean
Returns

Promise<string | null | undefined>

Defined in

browser/sync/authentication_manager.ts:25


ConnectionState

Ƭ ConnectionState: Object

State describing the client's connection with the Convex backend.

Type declaration

NameTypeDescription
hasInflightRequestsboolean-
isWebSocketConnectedboolean-
timeOfOldestInflightRequestDate | null-
hasEverConnectedbooleanTrue if the client has ever opened a WebSocket to the "ready" state.
connectionCountnumberThe number of times this client has connected to the Convex backend. A number of things can cause the client to reconnect -- server errors, bad internet, auth expiring. But this number being high is an indication that the client is having trouble keeping a stable connection.
connectionRetriesnumberThe number of times this client has tried (and failed) to connect to the Convex backend.
inflightMutationsnumberThe number of mutations currently in flight.
inflightActionsnumberThe number of actions currently in flight.

Defined in

browser/sync/client.ts:137


FunctionResult

Ƭ FunctionResult: FunctionSuccess | FunctionFailure

The result of running a function on the server.

If the function hit an exception it will have an errorMessage. Otherwise it will produce a Value.

Defined in

browser/sync/function_result.ts:11


OptimisticUpdate

Ƭ OptimisticUpdate<Args>: (localQueryStore: OptimisticLocalStore, args: Args) => void

Type parameters

NameType
Argsextends Record<string, Value>

Type declaration

▸ (localQueryStore, args): void

A temporary, local update to query results within this client.

This update will always be executed when a mutation is synced to the Convex server and rolled back when the mutation completes.

Note that optimistic updates can be called multiple times! If the client loads new data while the mutation is in progress, the update will be replayed again.

Parameters
NameTypeDescription
localQueryStoreOptimisticLocalStoreAn interface to read and edit local query results.
argsArgsThe arguments to the mutation.
Returns

void

Defined in

browser/sync/optimistic_updates.ts:90


QueryJournal

Ƭ QueryJournal: string | null

A serialized representation of decisions made during a query's execution.

A journal is produced when a query function first executes and is re-used when a query is re-executed.

Currently this is used to store pagination end cursors to ensure that pages of paginated queries will always end at the same cursor. This enables gapless, reactive pagination.

null is used to represent empty journals.

Defined in

browser/sync/protocol.ts:112


QueryToken

Ƭ QueryToken: string

A string representing the name and arguments of a query.

This is used by the BaseConvexClient.

Defined in

browser/sync/udf_path_utils.ts:27


UserIdentityAttributes

Ƭ UserIdentityAttributes: Omit<UserIdentity, "tokenIdentifier">

Defined in

server/authentication.ts:146