Skip to main content
The browser module provides clients for accessing Convex from browser JavaScript applications without React.

Installation

Importing

If you are using React, use the convex/react module instead for better integration with React’s rendering and state management.

ConvexClient

A WebSocket-based client that subscribes to queries and executes mutations and actions. Provides reactive updates when query results change.

Basic usage

Constructor options

Options:
  • disabled - Disables subscriptions (useful for SSR)
  • unsavedChangesWarning - Prompts users about unsaved changes before leaving

Subscribing to queries

The onUpdate method subscribes to a query and calls a callback when results change:
Return value: The return value is both a function and an object:

Executing mutations

Executing actions

One-time queries

Authentication

Set authentication with an async token fetcher:

Connection state

Paginated queries (experimental)

Cleanup

Always close the client when done:

ConvexHttpClient

An HTTP-based client for executing queries, mutations, and actions without maintaining a WebSocket connection. Suitable for server-side code or applications that don’t need real-time updates.

Basic usage

Constructor options

Executing queries

Executing mutations

Mutations are queued by default to ensure ordered execution:

Executing actions

Authentication

Consistent queries (experimental)

Execute multiple queries at the same timestamp:
Consistent queries have a 30-second time limit. Create a new client for a fresh timestamp.

Choosing a client

Use ConvexClient when:
  • Building a browser application without React
  • You need real-time updates
  • You want to subscribe to query changes
Use ConvexHttpClient when:
  • Running in serverless functions or edge workers
  • Making one-off requests
  • You don’t need real-time updates
  • Minimizing connection overhead is important

Error handling

Type safety

All clients use generated TypeScript types:

BaseConvexClient

For advanced use cases, you can extend BaseConvexClient to build custom clients:

Best practices

  • Store deployment URLs in environment variables
  • Always close clients when done to prevent memory leaks
  • Use ConvexClient for browser apps that need reactivity
  • Use ConvexHttpClient for server-side code
  • Handle errors appropriately for mutations and actions
  • For React applications, use convex/react instead
  • Implement connection state UI for better user experience