flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

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

Open FRSpeed opened this issue 1 year ago • 4 comments

  • [x] I have read the Getting Started section
  • [x] I have already searched for the same problem

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

  • CreateWindowAction.request.url return null

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");
}
</script>

<body>
page 1
<button type="button" onclick="openPage()">open window.open</button>
</body>
</html>
  1. 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

image

Stacktrace/Logcat

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}

FRSpeed avatar Apr 28 '23 10:04 FRSpeed

👋 @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!

github-actions[bot] avatar Apr 28 '23 10:04 github-actions[bot]

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

gkhnbks avatar May 15 '23 13:05 gkhnbks

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?

muhammadusama-mset avatar May 01 '24 05:05 muhammadusama-mset

Hi, same problem here with latest version.

arioul89 avatar Aug 08 '24 15:08 arioul89