InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable javascript error

半城伤御伤魂 提交于 2019-12-13 05:34:00

问题


I'm trying to follow this answer

https://stackoverflow.com/a/28213834/632224

to get some files hashed in browser, but when i replace

"importScripts('http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js');"+

with something like "importScripts('path to local copy of md5.js');"+ i'm getting error InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable in blob line 1.

Here is content of that blob:

importScripts('path to local copy of md5.js');var md5, cryptoType;self.onmessage = function webWorkerOnMessage(e){
    function arrayBufferToWordArray(ab) {
        var i8a = new Uint8Array(ab);
        var a = [];
        for (var i = 0; i < i8a.length; i += 4) {
          a.push(i8a[i] << 24 | i8a[i + 1] << 16 | i8a[i + 2] << 8 | i8a[i + 3]);
        }
        return CryptoJS.lib.WordArray.create(a, i8a.length);
    }
    if (e.data.type === "create") {
        md5 = CryptoJS.algo.MD5.create();
        postMessage({type: "create"});
    } else if (e.data.type === "update") {
        md5.update(arrayBufferToWordArray(e.data.chunk));
        postMessage({type: "update"});
    } else if (e.data.type === "finish") {
        postMessage({type: "finish", hash: ""+md5.finalize()});
    }
}

UPDATE: FF throws error from question title, when i try code in chrome, i'm getting Uncaught [object DOMException] error.

I have tried different ways to enter path, both windows and linux style, tried both relative and full path, but it's not working.

I guess, for some reason, code can't find file on disk, but don't know why. Can someone help with this?

来源:https://stackoverflow.com/questions/35691000/invalidstateerror-an-attempt-was-made-to-use-an-object-that-is-not-or-is-no-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!