-
Couldn't load subscription status.
- Fork 29.4k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfyi-iosFor the attention of iOS platform teamFor the attention of iOS platform teamp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Description
Steps to reproduce
- Create a WebViewController instance in initState()
- Immediately call setJavaScriptMode(JavaScriptMode.unrestricted)
- Run the app on a real device or simulator with iOS 18.5
- Hot restart or restart in debug mode
- Observe the crash
Expected results
No crash occurs. The WebViewController should safely initialize and configure JavaScript mode, even if the widget is still being built.
Actual results
PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null))
WKWebViewConfiguration.getDefaultWebpagePreferences (package:webview_flutter_wkwebview/src/common/web_kit.g.dart:3611:7)
WebKitWebViewController.setJavaScriptMode (package:webview_flutter_wkwebview/src/webkit_webview_controller.dart:598:11)
Code sample
Code sample
class WebViewScreen extends StatefulWidget {
const WebViewScreen({super.key, required this.initialUrl});
final String initialUrl;
@override
State<WebViewScreen> createState() => _WebViewScreenState();
}
class _WebViewScreenState extends State<WebViewScreen> with WidgetsBindingObserver {
late final WebViewController controller;
@override
void initState() {
super.initState();
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted) // ← causes crash on iOS in debug
..setUserAgent('Custom UA');
controller.loadRequest(
Uri.parse(widget.initialUrl),
headers: <String, String>{
'Authorization': 'External <access_token>',
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: WebViewWidget(controller: controller),
);
}
}Screenshots or Video
No response
Logs
Logs
PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null))
WKWebViewConfiguration.getDefaultWebpagePreferences (package:webview_flutter_wkwebview/src/common/web_kit.g.dart:3611:7)
WebKitWebViewController.setJavaScriptMode (package:webview_flutter_wkwebview/src/webkit_webview_controller.dart:598:11)Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.4.1 24E263 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.99.3)
[✓] Connected device (4 available)
[✓] Network resourcesMetadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfyi-iosFor the attention of iOS platform teamFor the attention of iOS platform teamp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds