Closed bezreyhan closed 9 years ago
works for me in chrome http://requirebin.com/?gist=41d322190bbf845b8a25
what exactly are you doing because the example you gave doesn't look like it's in javascript
sorry about the confusion - I had pasted the coffee-script from my file. Also, the console.log was supposed to be on a separate line. I edited the issue.
I'm not sure what's causing the problem. I'm simply requiring the module like all the other modules I'm browserifying.
I also ran this check before the require statement and everything seems fine:
if(crypto && crypto.getRandomValues) {
console.log('hi'); // returns hi
}
hm, so does the link above work for you? and are you able to open up dev tools and a put a break point in?
yea it does. But I just tried running it again with global.crypto
and I got undefined
Maybe the coffee-script compiler is thrown off by that?
yup I bet the compiler is seeing global and thinking you want to declare that variable, solution: compile to coffeescirpt then run program
er from coffeescript
Yea this is a coffee-script thing. I just tried it in a js repo and it worked fine.
Though, I am compiling to js before running it. Before I run it in the browser, I am browserifying the file with the coffeeify transformation. (I don't believe you can run plain coffee-script in the browser)
Should we change this file to search for the window
object instead if global
: https://github.com/crypto-browserify/randombytes/blob/master/browser.js#L3
Since this is a browser specific file it should be ok. This way we won't have to rely on browserify to set global
as an alias for window
ok scratch what I said. I just started a coffee repo and ran through the same steps of requiring randombytes and running it through browserify and coffeeify. Everything worked fine. There must be something weird going on in my project. I'll try to see if I can figure
As this can run in a worker too do window wouldn't work either. This is something that you are doing that is going to break a lot of other browserify code fyi you should probably make sure coffeeify is only running on .coffee files
On Thu, Mar 26, 2015, 7:02 PM bezreyhan notifications@github.com wrote:
Yea this is a coffee-script thing. I just tried it in a js repo and it worked fine.
Though, I am compiling to js before running it. Before I run it in the browser, I am browserifying the file with the coffeeify transformation. (I don't believe you can run plain coffee-script in the browser)
Should we change this file to search for the window object instead if global: https://github.com/crypto-browserify/randombytes/blob/master/browser.js#L3
Since this is a browser specific file it should be ok. This way we won't have to rely on browserify to set global as an alias for window
— Reply to this email directly or view it on GitHub https://github.com/crypto-browserify/randombytes/issues/2#issuecomment-86748907 .
All my files are written in coffee. I'm starting to think that this is not a coffee-script issue since when I created a new coffee repo and ran it through coffeeify, randombytes worked fine.
Am I understanding you correctly?
@calvinmetcalf would it be more correct to use window
over global
?
No global is the preferred way in browserify so it will work in a web worker
On Thu, Mar 26, 2015, 9:56 PM Daniel Cousens notifications@github.com wrote:
@calvinmetcalf https://github.com/calvinmetcalf would it be more correct to use window over global?
— Reply to this email directly or view it on GitHub https://github.com/crypto-browserify/randombytes/issues/2#issuecomment-86788001 .
@calvinmetcalf so this issue was caused by a separate library that was not being browserified, but rather being loaded in through a script tag. That library exposed a global variable named "global", thus throwinf off how browserify aliases the window object. Nevertheless, thanks for the time and help.
@bezreyhan so the solution there is to just browserify everything!
It seems that Firefox's web workers have not yet implemented crypto. randombytes throws Uncaught Error: secure random number generation not supported by this browser use chrome, FireFox or Internet Explorer 11
in a Firefox web worker.
https://bugzilla.mozilla.org/show_bug.cgi?id=842818
I'm guessing there is not a way to get around this?
@bezreyhan pass the necessary random data through a message?
@dcousens yea, that's what I've resorted to. Was hoping I could leave it in the worker but it doesn't seem like its going to work out that way.
@bezreyhan don't forget to send a bug report to Mozilla :)
I received this error in an up-to-date version of Chrome (Version 41.0.2272.104):
Uncaught Error: secure random number generation not supported by this browser use chrome, FireFox or Internet Explorer 11
after running
However,
crypto.randomBytes
worked fine.