Skip to content

Commit efdd809

Browse files
updating the readme
1 parent 9d294bb commit efdd809

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

examples/web/RunAnywhereAI/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ export default defineConfig({
6060
},
6161
server: {
6262
headers: {
63-
// Required for SharedArrayBuffer (pthreads) and WASM threads
63+
// Cross-Origin Isolation — required for SharedArrayBuffer / multi-threaded WASM.
64+
// Without these headers the SDK falls back to single-threaded mode.
65+
// Safari doesn't support 'credentialless'; see public/coi-serviceworker.js
66+
// and the ensureCrossOriginIsolation() call in src/main.ts for the fallback.
6467
'Cross-Origin-Opener-Policy': 'same-origin',
65-
// 'credentialless' allows cross-origin resource loading
6668
'Cross-Origin-Embedder-Policy': 'credentialless',
6769
},
6870
fs: {

sdk/runanywhere-web/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ The pre-built WASM includes llama.cpp (LLM/VLM), whisper.cpp (STT), and sherpa-o
116116
npm install @runanywhere/web
117117
```
118118

119-
### Serve WASM Files
119+
### Serve WASM Files + Cross-Origin Isolation
120120

121121
The package includes pre-built WASM files in `node_modules/@runanywhere/web/wasm/`. Configure your bundler to serve these as static assets.
122122

123+
> **Important:** Your server **must** set Cross-Origin Isolation headers for `SharedArrayBuffer` and multi-threaded WASM to work. Without these headers the SDK falls back to single-threaded mode, which is significantly slower. See [Cross-Origin Isolation Headers](#cross-origin-isolation-headers) for all platforms (Nginx, Vercel, Netlify, Cloudflare, AWS, Apache).
124+
123125
**Vite:**
124126

125127
```typescript
@@ -128,6 +130,7 @@ export default defineConfig({
128130
assetsInclude: ['**/*.wasm'],
129131
server: {
130132
headers: {
133+
// Required for SharedArrayBuffer / multi-threaded WASM
131134
'Cross-Origin-Opener-Policy': 'same-origin',
132135
'Cross-Origin-Embedder-Policy': 'credentialless',
133136
},
@@ -145,9 +148,18 @@ module.exports = {
145148
{ test: /\.wasm$/, type: 'asset/resource' },
146149
],
147150
},
151+
devServer: {
152+
headers: {
153+
// Required for SharedArrayBuffer / multi-threaded WASM
154+
'Cross-Origin-Opener-Policy': 'same-origin',
155+
'Cross-Origin-Embedder-Policy': 'credentialless',
156+
},
157+
},
148158
};
149159
```
150160

161+
> **Safari/iOS:** Safari does not support `credentialless` COEP. Use the COI service worker pattern shown in the [demo app](../../examples/web/RunAnywhereAI/) — it intercepts responses and injects `require-corp` headers at runtime. See `public/coi-serviceworker.js` and the `ensureCrossOriginIsolation()` call in `src/main.ts`.
162+
151163
---
152164

153165
## Quick Start

sdk/runanywhere-web/packages/core/src/Infrastructure/DeviceCapabilities.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export async function detectCapabilities(): Promise<WebCapabilities> {
8080
`Cores=${capabilities.hardwareConcurrency}`,
8181
);
8282

83+
if (!capabilities.isCrossOriginIsolated) {
84+
logger.warning(
85+
'Cross-Origin Isolation is NOT enabled. SharedArrayBuffer and multi-threaded WASM ' +
86+
'will be unavailable. Set these HTTP headers on your server:\n' +
87+
' Cross-Origin-Opener-Policy: same-origin\n' +
88+
' Cross-Origin-Embedder-Policy: credentialless\n' +
89+
'See: https://github.com/AnywhereAI/runanywhere-sdks/tree/main/sdk/runanywhere-web#cross-origin-isolation-headers',
90+
);
91+
}
92+
8393
return capabilities;
8494
}
8595

0 commit comments

Comments
 (0)