# The web fallback

`webBridge()` is the bridge for a plain browser build, and it passes the same contract suite
as every native shell. That is what keeps the web build working: the game calls one API
everywhere, and on the web it gets this.

```typescript
import { createNative, webBridge } from 'tosijs-native'
import config from './tosijs-native.config'

const native = await createNative(config, webBridge())
```

- **Saves** go to `localStorage`, or to memory where `localStorage` is missing or refuses
  writes (private mode, a locked-down web view). `info().durability` says which.
- **Achievements** are recorded in the same storage.
- **Purchases** are refused by default (`failed`), because the web build has no store.
  `purchases: 'approve'` makes every purchase succeed (for development and for the contract
  suite), and `purchases: 'cancel'` makes every one cancel.
- **Lifecycle** follows `document.visibilityState`.
- **Saves written in another tab** arrive as `store.changed` (the browser's `storage`
  event), which is the web's version of a save from another device. `cloudSaves` itself is
  never reported: `localStorage` does not leave the browser.
- **What is owned changing in another tab** arrives as `owned`, by the same event: the
  web's version of a purchase approved, or refunded, while the game was not looking.
- **Files** go to the browser's private file store (see Files on the web), or to memory
  where it has none. Pass `files: memoryFiles()` for a bridge that forgets them.
- **Permissions** are the browser's: `Notification.permission`, the Permissions API, and
  `getUserMedia` or `DeviceMotionEvent.requestPermission()` to ask.
- **Location** is `navigator.geolocation`, only while the page is open (`watch` answers
  `foreground`). An app that declares `approximate` gets fixes rounded to about a kilometre.
- **Notifications** use the `Notification` API and a timer, so one only fires **while the
  page is open**; a browser has no way to schedule one for a closed page without a server.
- **Capabilities** use the browser's own APIs where it has them, and are reported absent
  where it does not: `keepAwake` is the Screen Wake Lock API, `share` is `navigator.share`,
  and `openExternal` opens a new tab.

`capabilities` is the config's `capabilities`. Pass it and the bridge refuses what the config
does not declare, exactly as a native shell does; leave it out and nothing is refused, which
suits a page that has no config to hand. On the web the gate protects nothing (the page is
the app), so it exists to make a mistake fail in the browser too, before it fails in a shell.

`storage`, `document`, `navigator` and `window` default to the globals; pass
`memoryStorage()` for a bridge that forgets everything when the page closes.

Storage keys are namespaced (`namespace` defaults to `tosijs-native`), and the bridge's own
records are kept apart from game saves, so `store.keys` lists only what the game wrote.

## memoryStorage

The slice of `localStorage` the bridge uses, backed by a `Map`. Also what the bridge falls
back to.
