Skip to content

Commit 3f8e409

Browse files
brentvatneLinusU
andauthored
🎉 Add support for bridgeless mode (LinusU#57)
* Support bridgeless mode * Follow standard style --------- Co-authored-by: Linus Unnebäck <[email protected]>
1 parent f5f21c7 commit 3f8e409

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,27 @@ function getRandomValues (array) {
5656
return array
5757
}
5858

59-
// Calling getRandomBase64 in debug mode leads to the error
59+
// Calling getRandomBase64 in remote debugging mode leads to the error
6060
// "Calling synchronous methods on native modules is not supported in Chrome".
61-
// So in that specific case we fall back to just using Math.random.
62-
if (__DEV__) {
63-
if (typeof global.nativeCallSyncHook === 'undefined') {
64-
return insecureRandomValues(array)
65-
}
61+
// So in that specific case we fall back to just using Math.random().
62+
if (isRemoteDebuggingInChrome()) {
63+
return insecureRandomValues(array)
6664
}
6765

6866
base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength))
6967

7068
return array
7169
}
7270

71+
function isRemoteDebuggingInChrome () {
72+
// Remote debugging in Chrome is not supported in bridgeless
73+
if ('RN$Bridgeless' in global && RN$Bridgeless === true) {
74+
return false
75+
}
76+
77+
return __DEV__ && typeof global.nativeCallSyncHook === 'undefined'
78+
}
79+
7380
if (typeof global.crypto !== 'object') {
7481
global.crypto = {}
7582
}

0 commit comments

Comments
 (0)