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.
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 wherelocalStorageis missing or refuses writes (private mode, a locked-down web view).info().durabilitysays 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), andpurchases: 'cancel'makes every one cancel. - Lifecycle follows
document.visibilityState. - Saves written in another tab arrive as
store.changed(the browser'sstorageevent), which is the web's version of a save from another device.cloudSavesitself is never reported:localStoragedoes 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, andgetUserMediaorDeviceMotionEvent.requestPermission()to ask. - Location is
navigator.geolocation, only while the page is open (watchanswersforeground). An app that declaresapproximategets fixes rounded to about a kilometre. - Notifications use the
NotificationAPI 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:
keepAwakeis the Screen Wake Lock API,shareisnavigator.share, andopenExternalopens 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.