diff options
author | hackademix | 2018-07-03 19:35:33 +0200 |
---|---|---|
committer | hackademix | 2018-07-03 19:35:33 +0200 |
commit | 8ae9513f75fa8c975a5960684bfaa575ceaa6f6d (patch) | |
tree | bb127db8c4cae2f173b661c52e91a2cb1b225b6d /src/lib/uuid.js | |
parent | 5c71c94a13554adbfcd2baa0dc53f0a4be4b92ba (diff) | |
download | noscript-8ae9513f75fa8c975a5960684bfaa575ceaa6f6d.tar.gz noscript-8ae9513f75fa8c975a5960684bfaa575ceaa6f6d.tar.xz noscript-8ae9513f75fa8c975a5960684bfaa575ceaa6f6d.zip |
Provide a uuid function fallback which doesn't fail in the Tor Browser.
Diffstat (limited to 'src/lib/uuid.js')
-rw-r--r-- | src/lib/uuid.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/uuid.js b/src/lib/uuid.js index d809437..43f6d50 100644 --- a/src/lib/uuid.js +++ b/src/lib/uuid.js @@ -1,6 +1,15 @@ 'use strict'; + function uuid() { - return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, - c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4) - .toString(16)); + try { + return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, + c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4) + .toString(16)); + } catch (e) { + // fallback, as the Tor Browser seems to fail above + uuid = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + } } |