diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/initialization.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/initialization.dart index bbf346d3c2..49dcb53dce 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/initialization.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/initialization.dart @@ -273,8 +273,18 @@ Future _downloadAssetFonts() async { void _addUrlStrategyListener() { jsSetUrlStrategy = allowInterop((JsUrlStrategy? jsStrategy) { - customUrlStrategy = - jsStrategy == null ? null : CustomUrlStrategy.fromJs(jsStrategy); + if (jsStrategy == null) { + customUrlStrategy = null; + } else { + // Because `JSStrategy` could be anything, we check for the + // `addPopStateListener` property and throw if it is missing. + if (!hasJsProperty(jsStrategy, 'addPopStateListener')) { + throw StateError( + 'Unexpected JsUrlStrategy: $jsStrategy is missing ' + '`addPopStateListener` property'); + } + customUrlStrategy = CustomUrlStrategy.fromJs(jsStrategy); + } }); registerHotRestartListener(() { jsSetUrlStrategy = null; diff --git a/engine/src/flutter/lib/web_ui/test/window_test.dart b/engine/src/flutter/lib/web_ui/test/window_test.dart index 44a6fe6b6e..b356b6fba1 100644 --- a/engine/src/flutter/lib/web_ui/test/window_test.dart +++ b/engine/src/flutter/lib/web_ui/test/window_test.dart @@ -435,6 +435,7 @@ void testMain() { expect(() => jsSetUrlStrategy(123), throwsA(anything)); expect(() => jsSetUrlStrategy('foo'), throwsA(anything)); expect(() => jsSetUrlStrategy(false), throwsA(anything)); + expect(() => jsSetUrlStrategy([]), throwsA(anything)); }); test('cannot set url strategy after it is initialized', () async {