pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.26k stars 1.6k forks source link

window.open popup not return correct URL in onCreateWindow event function #1633

Open FRSpeed opened 1 year ago

FRSpeed commented 1 year ago

Environment

Technology Version
Flutter version 3.7.5-stable
Plugin version ^5.7.2+3
Android version 10

Device information:

Description

onclick function that use window.open not return URL as expected in onCreateWindow

Expected behavior: CreateWindowAction.request.url inside onCreateWindow should return correct url. For example when onclick button function call window.open("https://www.w3schools.com", "", "width=400,height=400"); CreateWindowAction.request.url should return https://www.w3schools.com

Current behavior: onCreateWindow

Steps to reproduce

Example: window.open("https://www.w3schools.com", "", "width=400,height=400");

  1. create simple html page in server
    
    <html>
    <head>
    <title>page 1 </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <script language="javascript">

function openPage(){ window.open("https://www.w3schools.com", "", "width=200,height=100"); }

page 1

2. Use this code in Flutter

InAppWebView( initialUrlRequest: URLRequest(url: Uri.parse(value),headers: _cookieHeader), initialOptions: options, onWebViewCreated: (controller) { webViewController = controller; print('#onWebViewCreated'); }, onCreateWindow: (controller, cwa ) async{ Uri? aaa = await controller.getUrl(); String? bbb = await controller.getHtml(); Uri? oriUrl = await controller.getOriginalUrl(); print('### web view : ${cwa.request.toJson()}'); print('### get URL : $aaa'); print('### get HTML : $bbb'); print('### ori Url : $oriUrl'); return true; }, androidOnPermissionRequest: (controller, origin, resources) async { return PermissionRequestResponse( resources: resources, action: PermissionRequestResponseAction.GRANT); }, shouldOverrideUrlLoading: (controller, navigationAction) async { var uri = navigationAction.request.url!; var url = await controller.getUrl(); print('#shouldOverrideUrlLoading uri:$uri'); print('#SOUL:navigationAction: ${navigationAction.toJson()}'); print('#SOUL controller.url:$url'); if (![ "http", "https", "file", "chrome", "data", "javascript", "about"].contains(uri.scheme)) { return NavigationActionPolicy.CANCEL; }

return NavigationActionPolicy.ALLOW;

}, )


## Images <!-- if available, else delete -->  
![image](https://user-images.githubusercontent.com/132059210/235122425-01cfc9da-6564-44f1-ac58-6a956f074f51.png)

## Stacktrace/Logcat <!-- if available, else delete -->  

W/chromium( 2463): [WARNING:aw_contents.cc(1148)] Blocking popup window creation as an outstanding popup window is still pending. W/cr_WebSettings( 2463): getForceDark() is a no-op in an app with targetSdkVersion>=T D/EGL_emulation( 2463): app_time_stats: avg=592.32ms min=186.41ms max=998.23ms count=2 I/flutter ( 2463): ### web view : {url: null, headers: null, method: GET, body: null, iosAllowsCellularAccess: null, iosAllowsConstrainedNetworkAccess: null, iosAllowsExpensiveNetworkAccess: null, iosCachePolicy: null, iosHttpShouldHandleCookies: null, iosHttpShouldUsePipelining: null, iosNetworkServiceType: null, iosTimeoutInterval: null, iosMainDocumentURL: null}

github-actions[bot] commented 1 year ago

👋 @FRSpeed

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

gkhnbks commented 1 year ago

I also have the same problem. cant get the url or html after opening webview. ps: only on flutter web.

muhammadusama-mset commented 5 months ago

I also have the same problem. cant get the url or html after opening webview. ps: only on flutter web.

Did you find any solution for this?

arioul89 commented 2 months ago

Hi, same problem here with latest version.