Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workers-playground/gotchas.md
1# Workers Playground Gotchas23## Platform Limitations45| Limitation | Impact | Workaround |6|------------|--------|------------|7| Safari broken | Preview fails | Use Chrome/Firefox/Edge |8| TypeScript unsupported | TS syntax errors | Write plain JS or use JSDoc |9| No bindings | `env` always `{}` | Mock data or use external APIs |10| No env vars | Can't access secrets | Hardcode for testing |1112## Common Runtime Errors1314### "Response body already read"1516```javascript17// ❌ Body consumed twice18const body = await request.text();19await fetch(url, { body: request.body }); // Error!2021// ✅ Clone first22const clone = request.clone();23const body = await request.text();24await fetch(url, { body: clone.body });25```2627### "Worker exceeded CPU time"2829**Limit:** 10ms (free), 30s default / 5min max (paid)3031```javascript32// ✅ Move slow work to background33ctx.waitUntil(fetch('https://analytics.example.com', {...}));34return new Response('OK'); // Return immediately35```3637### "Too many subrequests"3839**Limit:** 50 (free), 1000 (paid)4041```javascript42// ❌ 100 individual fetches43// ✅ Batch into single API call44await fetch('https://api.example.com/batch', {45body: JSON.stringify({ ids: [...] })46});47```4849## Best Practices5051```javascript52// Clone before caching53await cache.put(request, response.clone());54return response;5556// Validate input early57if (request.method !== 'POST') return new Response('', { status: 405 });5859// Handle errors60try { ... } catch (e) {61return Response.json({ error: e.message }, { status: 500 });62}63```6465## Limits6667| Resource | Free | Paid |68|----------|------|------|69| CPU time | 10ms | 30s (default), 5min (max) |70| Memory | 128 MB | 128 MB |71| Subrequests | 50 | 10,000 |7273## Browser Support7475| Browser | Status |76|---------|--------|77| Chrome | ✅ Recommended |78| Firefox | ✅ Works |79| Edge | ✅ Works |80| Safari | ❌ Broken |8182## Debugging8384```javascript85console.log('URL:', request.url); // View in browser DevTools Console86```8788**Note:** `console.log` works in playground. For production, use Logpush or Tail Workers.89