justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.73k stars 3.72k forks source link

Not working in Microsoft Edge - lack of TextEncoder support (since 0.20.1) #340

Open noahlevenson opened 5 years ago

noahlevenson commented 5 years ago

After bumping to v0.20.1, using Edge 44.18362.1.0, the console emits the following error:

'TextEncoder' is not defined

Microsoft's delightful Edge browser doesn't currently support TextEncoder or TextDecoder: https://caniuse.com/#feat=textencoder

This fixes it:


                TextEncoder = function TextEncoder() {

        }

        TextEncoder.prototype.encode = function(s) {
            const e = new Uint8Array(s.length);

            for (let i = 0; i < s.length; i += 1) {
                e[i] = s.charCodeAt(i);
            }

            return e;
        }

        TextDecoder = function TextDecoder() {

        }

        TextDecoder.prototype.decode = function(arr) {
            let d = "";

            for (let i = 0; i < arr.length; i += 1) {
                d += String.fromCharCode(arr[i]);
            }

            return d;
        } 
SaadAhmadSaddiqui commented 4 years ago

I'm working with Next.JS and there are packages in my project that have text encoder. How can I use this in my project?