flutter_inappwebview
flutter_inappwebview copied to clipboard
Windows opened by a webpage aren't able to close
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
When a new window opens, webview redirects to that page. But when the window closes, it fails to close with following error in console:
- iOS: "Can't close the window since it was not opened by JavaScript"
- Android: "Scripts may close only the windows that were opened by them", "Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.udemy.com/') does not match the recipient window's origin ('https://accounts.google.com/')."
Expected Behavior
Window should close i.e webview should redirect back to the previous webpage window.
Steps with code example to reproduce
Steps with code example to reproduce
- Run the following example app on android or ios.
- Try signing in with Google.
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
WebUri? url;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(url?.host ?? ''),
),
body: InAppWebView(
initialUrlRequest: URLRequest(url: WebUri('https://www.udemy.com')),
initialSettings: InAppWebViewSettings(
cacheEnabled: true,
databaseEnabled: true,
domStorageEnabled: true,
sharedCookiesEnabled: true,
userAgent: 'Mozilla/5.0 (Linux; Android 14; Pixel 8a Build/AP2A.240905.003.A1) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/129.0.6668.100 Mobile Safari/537.36',
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
supportMultipleWindows: true,
isInspectable: true,
),
onLoadStart: (controller, url) {
setState(() {
this.url = url;
});
},
),
);
}
}
Stacktrace/Logs
Stacktrace/Logs
NA
Flutter version
v3.24.3
Operating System, Device-specific and/or Tool
Occurred on Android 14 and iPadOS 18.0.1
Plugin version
v6.1.5
Additional information
I tried logging in using google on udemy.com. Window closes but login fails with "Scripts may close only the windows that were opened ..." error, and on iOS its stuck on google's loading page with "Can't close the window since it was not opened by JavaScript" error.
Self grab
- [X] I'm ready to work on this issue!