Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows opened by a webpage aren't able to close #2349

Open
2 tasks done
predatorx7 opened this issue Oct 16, 2024 · 1 comment
Open
2 tasks done

Windows opened by a webpage aren't able to close #2349

predatorx7 opened this issue Oct 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@predatorx7
Copy link

predatorx7 commented Oct 16, 2024

Is there an existing issue for this?

  • 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

  • I'm ready to work on this issue!
@predatorx7 predatorx7 added the bug Something isn't working label Oct 16, 2024
@pichillilorenzo
Copy link
Owner

You should implement the onCreateWindow event to implement your logic to show a new popup window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants