Skip to content

Random.secure() does not work in browser after packaged #14

Description

@TheBosZ

Because of how the self variable is created, any access to self.crypto throws an Uncaught TypeError: Illegal invocation exception.

This will happen when the Random.secure() constructor is called. It compiles to Javascript that looks like this:

var $crypto = self.crypto;
      if ($crypto != null)
        if ($crypto.getRandomValues != null)
          return;
      throw H.wrapException(P.UnsupportedError$("No source of cryptographically secure random numbers available."));

But accessing crypto will throw.

You can try this yourself in Chrome:

  1. Open a dev console
  2. var a = Object.create(window);
  3. a.crypto
  4. Exception is thrown

According to this: uuidjs/uuid#256, it's because it's losing the Crypto context.

My hacky fix is to just make the first line be var self = global; and call it good.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions