docs/docs/00100-intro/00200-quickstarts/00180-browser.md
import { InstallCardLink } from "@site/src/components/InstallCardLink"; import { StepByStep, Step, StepText, StepCode } from "@site/src/components/Steps";
Get a SpacetimeDB app running in the browser with inline JavaScript.
This will start the local SpacetimeDB server, publish your module, and generate TypeScript client bindings.
</StepText>
<StepCode>
spacetime dev --template browser-ts
</StepCode>
The JavaScript code runs inline in a script tag, using the bundled `DbConnection` class.
:::tip
The browser IIFE bundle also exposes the generated `tables` query builders, so you can use query-builder subscriptions here too.
:::
</StepText>
<StepCode>
<!-- Load the bundled bindings -->
<script src="dist/bindings.iife.js"></script>
<script>
const HOST = 'ws://localhost:3000';
const DB_NAME = 'my-spacetime-app';
const TOKEN_KEY = `${HOST}/${DB_NAME}/auth_token`;
const conn = DbConnection.builder()
.withUri(HOST)
.withDatabaseName(DB_NAME)
.withToken(localStorage.getItem(TOKEN_KEY))
.onConnect((conn, identity, token) => {
localStorage.setItem(TOKEN_KEY, token);
console.log('Connected:', identity.toHexString());
// Subscribe to tables
conn.subscriptionBuilder()
.onApplied(() => {
for (const person of conn.db.person.iter()) {
console.log(person.name);
}
})
.subscribe(tables.person);
})
.build();
</script>
</StepCode>
conn.db.person.onDelete((ctx, person) => { console.log('Removed:', person.name); });
</StepCode>
</Step>
</StepByStep>
## Next steps
- See the [Chat App Tutorial](../00300-tutorials/00100-chat-app.md) for a complete example
- Read the [TypeScript SDK Reference](../../00200-core-concepts/00600-clients/00700-typescript-reference.md) for detailed API docs