How to detect if a browser supports SharedArrayBuffer?
Asked Answered
G

1

6

I'm using ffmpeg.wasm in my site but it only works if the browser supports SharedArrayBuffer. Is there a simple way to test using javascript (browser js or nodejs) if the browser has support to it? One solution I thought was to compare the user agent with the list offered in this website but this would be too verbose and I'm guessing if there isn't a simpler way?

Geneva answered 10/10, 2021 at 12:53 Comment(4)
if( typeof SharedArrayBuffer !== 'undefined' ) { Daemon
Dare I ask what kind of performance you get from FFmpeg in WASM? Somehow I doubt you'll be able to do much in the way of H.265 encoding with a single JS thread.Daemon
I'm using to convert mp4 videos to hls format to offload this work from my server to the client, but indeed is kinda slowGeneva
MP4 and HLS are orthogonal. You can serve MP4 using HLS. You do not need to transcode files either.Daemon
G
-1

You can do all that but the easiest way of finding out is just checking here, but if you want to do it runtime you can add this line of code in your browser

try{
   var sab = new SharedArrayBuffer(1024);
   if(sab===undefined)throw new Error('not supported')
}
catch(e){
alert('browser doesnot support SharedArrayBuffer: ",e)
}
Glaciology answered 10/10, 2021 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.