diff --git a/.github/workflows/chrome.workflow.yml b/.github/workflows/chrome.workflow.yml index 4e5bbafd..d7162520 100644 --- a/.github/workflows/chrome.workflow.yml +++ b/.github/workflows/chrome.workflow.yml @@ -37,4 +37,4 @@ jobs: run: dart pub get - name: Test chrome - run: dart test -j 1 -p chrome + run: dart test --timeout 2x -j 1 -p chrome diff --git a/lib/src/platform_check/web.dart b/lib/src/platform_check/web.dart index 59ef673f..b23a7382 100644 --- a/lib/src/platform_check/web.dart +++ b/lib/src/platform_check/web.dart @@ -13,11 +13,19 @@ class PlatformWeb extends Platform { static bool useBuiltInRng = false; PlatformWeb() { + useBuiltInRng = false; try { Random.secure(); useBuiltInRng = true; } on UnsupportedError { - useBuiltInRng = false; + // Random.secure() normally throws this error if + // no cryptographically secure random number source is available. + } catch (e) { + // For Node.js with dart2js compiler, the UnknownJsTypeError error is expected. + // This error is internal to 'dart:_js_helper' so we need to inspect the runtimeType. + if (!(e.runtimeType.toString() == 'UnknownJsTypeError')) { + rethrow; + } } } @@ -48,7 +56,8 @@ class _JsBuiltInEntropySource implements EntropySource { @override Uint8List getBytes(int len) { return Uint8List.fromList( - List.generate(len, (i) => _src.nextInt(256))); + List.generate(len, (i) => _src.nextInt(256)), + ); } }