v148 · AI · JavaScript

Safety Harness

A test suite of 12 edge cases: API availability, empty input, emoji-only text, numbers, mixed scripts, very long text, and recovery from unsupported browsers. Run individually or all at once.

Checking Language Detector API availability…
12 Total
0 Pass
0 Fail
0 Warn
Ready. Press "Run all" or run individual tests.
Edge case tests
// Always feature-detect before using the API async function safeDetect(text) { // 1. Check API availability if (!('LanguageDetector' in globalThis)) { return { error: 'API not supported', fallback: heuristicDetect(text) }; } // 2. Check model readiness const availability = await LanguageDetector.availability(); if (availability === 'unavailable') { return { error: 'Model unavailable', fallback: heuristicDetect(text) }; } // 3. Guard empty / too-short text if (!text || text.trim().length < 3) { return { error: 'Text too short', result: null }; } // 4. Detect with error boundary try { const detector = await LanguageDetector.create(); const [top] = await detector.detect(text); return { result: top }; } catch (e) { return { error: e.message, fallback: heuristicDetect(text) }; } }

see also

references

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗