Uuid: [3.2.0] Illegal invocation at whatwgRNG

Created on 16 Jan 2018  ·  6Comments  ·  Source: uuidjs/uuid

Just installed the newest version 3.2.0 and I get this error in Chrome:

Uncaught TypeError: Illegal invocation
    at whatwgRNG (rng-browser.js:13)
    at v4 (v4.js:13)

Just messed around a bit and it looks like you can not assign the method getRandomValue from crypto or msCrypto to a variable (yeah...ugh, I guess it has to do with browser security).

if you go with

var myCrypto = crypto || msCrypto;

if (typeof myCrypto !== 'undefined') {
  var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
  module.exports = function whatwgRNG() {
    myCrypto.getRandomValues(rnds8);
    return rnds8;
  }
}

it should work.

Most helpful comment

парни, можно как-то по-быстрее это залить?

All 6 comments

Just found out about this bug as well.

The issue is not that you cannot assign getRandomValue to a variable, but that you have to make sure that this on invocation is a Crypto implementation.

const rng = crypto.getRandomValues;
const boundRng = crypto.getRandomValues.bind(crypto);
rng(new Uint8Array(16)) // does not work
rng.call(crypto, new Uint8Array(16)) // works
boundRng(new Uint8Array(16)) // works

:+1:

Greenkeeper bot reports all our libs broken since 3.2.0,

  • Error from chromium: Uncaught TypeError: Illegal invocation,
  • error from Firefox: TypeError: 'getRandomValues' called on an object that does not implement interface Crypto.

парни, можно как-то по-быстрее это залить?

For now I've just rolled back to 3.1.0 to get things working, but I assume this broke in the latest release.

Just found out this bug too. Version is also 3.2.0. Same errors as @flozz

I temporarily patch the script by forcing the execution of the else block (rng-browser.js).

Guys, you broke lib near our release. Happily we catch it before something bad happens. Stick to 3.1.0 now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guybedford picture guybedford  ·  9Comments

danactive picture danactive  ·  3Comments

ORESoftware picture ORESoftware  ·  5Comments

wesleytodd picture wesleytodd  ·  10Comments

ctavan picture ctavan  ·  9Comments