Determine browser capabilities

by morphcast

JavaScript

const checks = {
  bytedanceWebview:
    /BytedanceWebview/i.test(navigator.userAgent),

  wasm:
    typeof WebAssembly === 'object' &&
    typeof WebAssembly.instantiate === 'function',

  webgl: (() => {
    const canvas = document.createElement('canvas');
    return !!(window.WebGLRenderingContext &&
              canvas.getContext('webgl'));
  })(),

  camera:
    !!(navigator.mediaDevices &&
       navigator.mediaDevices.getUserMedia),

  indexedDB: (() => {
    try { return !!window.indexedDB; }
    catch { return false; }
  })()
};

window.alert(JSON.stringify(checks));