Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support web workers #65

Closed
jampy opened this issue Sep 1, 2016 · 4 comments
Closed

support web workers #65

jampy opened this issue Sep 1, 2016 · 4 comments
Labels

Comments

@jampy
Copy link

jampy commented Sep 1, 2016

Please add support for web workers.

cuid() currently throws an exception in web workers since navigator.mimeTypes is not available in that context.

Generally, for the fingerprint I suggest to collect various strings as a whole, gracefully handling errors, and then create a fingerprint out of that (arbitrary length) string using some hash function - like MD5, but perhaps something more lightweight.

Something in this direction:

api.fingerprint = function browserPrint() {

  var things = [];

  try {
    for (var i = 0; i < navigator.mimeTypes.length; i++) {
      things.push(navigator.mimeTypes[i]);
    }
  } catch (e) {
    // ignore errors
  }

  try {
    things.push(navigator.userAgent);
  } catch (e) {
    // ignore errors
  }

  // maybe add some more...

  things.push(api.globalCount());

  return someHashFunction(things.join(""));
};

I think you get the idea...

@ericelliott
Copy link
Collaborator

ericelliott commented Sep 1, 2016

I get the idea. Willing to look at a PR. I don't like the idea of using anything but the most rudimentary fast hashing algorithm (like, something that could be implemented in less than 10 LOC). cuid should remain a tiny dependency.

Also, I'd prefer not to use try/catch. We can check for feature availability without slowing things down with error catching.

While we're at it, we could use feature detection to eliminate the separate build for Node. Game on!

@ericelliott ericelliott added the bug label Sep 1, 2016
@jampy
Copy link
Author

jampy commented Sep 6, 2016

Okay, will think about a PR once I get some time perhaps (at the moment I'm using shortid)

As for the try/catch: AFAIK the fingerprint() function is only executed once, so I don't think speed is relevant.

@ericelliott
Copy link
Collaborator

Good point.

@ericelliott
Copy link
Collaborator

This should be fixed now. Reopen if you still have trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants