Why this happens
AI coding tools that do not reference the current docs at setup.despia.com or the Despia MCP server tend to build on older runtime patterns. The two below are by far the most common. Both produce code that either never detects the runtime or calls something that was never meant to be public. The fix is the same in every case: install the official SDK and detect the runtime from the user agent, never fromwindow.despia.
Mistake 1: legacy environment detection
Problem: Native calls never fire. The app behaves as if it is always running in a plain browser, even inside the Despia app. Cause: The generated code uses an outdated detection method, usually a check againstwindow.despia, a custom global, or a parsed platform string.
The only supported way to detect the runtime is the user agent. The despia string is present in navigator.userAgent when running inside Despia.
isDespia to gate every native call. Use isDespiaIOS or isDespiaAndroid only for platform-specific behaviour. No regex, no navigator.platform, no other parsing.
Mistake 2: targeting window.despia
Problem: Errors likedespia is not defined, typeof checks that are always falsy, or scheme calls that silently do nothing.
Cause: The code reads or writes window.despia directly to detect the runtime or trigger a feature.
window.despia is an internal runtime detail. The SDK sets it transiently while dispatching a scheme, and it is not a stable or public API. Detecting on it or assigning to it is unsupported and will break across runtime versions.
Wrong:
The correct setup
The SDK is the only supported entry point. Install it from NPM or load it from the CDN.- Bundle
- CDN
window.despia is the root cause of both mistakes above.
Stop the tool generating legacy code
The reliable fix is to give your AI tool the current API knowledge up front, so it never falls back to old patterns. Point it at the Despia MCP server, which gives the assistant full knowledge of thedespia-native API without pasting docs into the chat.
Remember
Detection is the user agent, nothing else.navigator.userAgent.toLowerCase().includes('despia')- Never detect on
window.despiaor a custom global
window.despia is internal.
- Never read it to check the runtime
- Never write to it to call a feature
- The official SDK is the only public entry point
- Add the MCP server at
https://setup.despia.com/mcp - Or paste the relevant docs into the chat