From 4bbe48946ae3f1e6039f34ca659875f307be1de3 Mon Sep 17 00:00:00 2001 From: abrahamjuliot Date: Fri, 11 Jun 2021 00:37:06 +0000 Subject: [PATCH] use more stable detection for strict mode #16 --- modules/helpers.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/helpers.js b/modules/helpers.js index d378dfe9..4adb7cc5 100644 --- a/modules/helpers.js +++ b/modules/helpers.js @@ -14,14 +14,25 @@ function getBraveMode() { strict: false } try { - // strict mode limits supported extensions - const canvas = document.createElement('canvas') - const gl = canvas.getContext('webgl') - const extensions = gl.getSupportedExtensions() - if ( - !extensions || ( - new Set(extensions).size == 1 && extensions[0] == 'WEBGL_debug_renderer_info') - ) { + // strict mode adds float frequency data AnalyserNode + const strictMode = () => { + const audioContext = ( + 'OfflineAudioContext' in window ? OfflineAudioContext : + 'webkitOfflineAudioContext' in window ? webkitOfflineAudioContext : + undefined + ) + if (!audioContext) { + return false + } + const context = new audioContext(1, 1, 44100) + const analyser = context.createAnalyser() + const data = new Float32Array(analyser.frequencyBinCount) + analyser.getFloatFrequencyData(data) + const strict = new Set(data).size > 1 // native only has -Infinity + return strict + } + + if (strictMode()) { mode.strict = true return mode }