Skip to content
New issue

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

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

Already on GitHub? # to your account

self.crypto.randomUUID is not a function #28

Closed
aamasri opened this issue Nov 28, 2024 · 4 comments
Closed

self.crypto.randomUUID is not a function #28

aamasri opened this issue Nov 28, 2024 · 4 comments

Comments

@aamasri
Copy link

aamasri commented Nov 28, 2024

Describe the bug
The package throws "TypeError: self.crypto.randomUUID is not a function" in unsecure (e.g. http://localhost) environments. This prevents the package form working in development

To Reproduce
Simply instantiating a dropzone:
const myDropzone = new Dropzone(target):

Browser / OS:

  • Latest Chrome, Firefox (on Mac Sonoma 14.6.1)

Suggested solution
Provide a polyfill for self.crypto.randomUUID for insecure environments (and older browsers). e.g.

if (typeof crypto.randomUUID !== 'function') {
  crypto.randomUUID = function() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random() * 16 | 0,
          v = c === 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
    });
  };
}

@NicolasCARPi
Copy link
Owner

Hello,

localhost is not insecure.

Locally-delivered resources such as those with http://127.0.0.1 URLs, http://localhost and http://*.localhost URLs (e.g. http://dev.whatever.localhost/), and file:// URLs are also considered to have been delivered securely.

source

So the behavior you observe is surprising.

Furthermore, a fallback was added in #24 and then refined in #27. These changes are simply not yet published in a stable version.

@aamasri
Copy link
Author

aamasri commented Nov 28, 2024

Thank you for maintaining this important package. I see that I have added a duplicate issue.

For your information, in development, we use a virtual host setup to map various projects to localhost and browsers are treating these virtual hosts as insecure when not served over HTTPS.

@aamasri aamasri closed this as completed Nov 28, 2024
@NicolasCARPi
Copy link
Owner

I've release 7.2.0 with these changes ;)

@aamasri
Copy link
Author

aamasri commented Nov 29, 2024

Amazing! Thank you.

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

No branches or pull requests

2 participants