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

[webview_flutter_wkwebview] Add webkit interface for showing javascript alert message #4555

Closed

Conversation

jsharp83
Copy link
Contributor

@jsharp83 jsharp83 commented Jul 24, 2023

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jsharp83 jsharp83 requested a review from cyanglaz as a code owner July 24, 2023 07:55
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@jsharp83 jsharp83 changed the title [webview_flutter_wkwebview] add functions to display a system popup using Javascript in iOS [webview_flutter_wkwebview] Add webkit interface for showing javascript alert message Jul 24, 2023
@jsharp83 jsharp83 force-pushed the add-ios-javascript-popup-interface branch 2 times, most recently from 8db3bc6 to 1933921 Compare July 26, 2023 21:20
@bparrishMines
Copy link
Contributor

@jsharp83 Thanks for the contribution! It looks like this feature is also supported on Android, onJSAlert, so we should add support for this in the common platform interface: webview_flutter_platform_interface.

See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins for more info on the process of doing this.

@jsharp83
Copy link
Contributor Author

jsharp83 commented Jul 27, 2023

@bparrishMines Thanks for the review.

Unlike iOS, in Android, System popup works without any additional implementation. I added a test code on webview_flutter_android example, so you can check it .

Even Android supports system popup in Javascript, someone wants to use flutter version of alert. If you think that it is necessary things to support, I will additionally implement it on android platform.

Thanks.

@jsharp83 jsharp83 force-pushed the add-ios-javascript-popup-interface branch from 9478648 to 5875cf9 Compare July 27, 2023 21:17
@jsharp83
Copy link
Contributor Author

@bparrishMines I checked onJsAlert, onJsConfirm and onJsPrompt function in WebChromeClient you already mentioned. I will implement a interface with it on WebChromeClientHostApiImpl.java

@jsharp83 jsharp83 force-pushed the add-ios-javascript-popup-interface branch from 5875cf9 to 2a1b164 Compare July 30, 2023 22:32
@bparrishMines
Copy link
Contributor

@jsharp83 Yea, I think we should still add a common platform interface for this method since it is supported on Android. The reason being that someone could want to override the default JS alerts on Android and we don't want to create an interface on iOS that is difficult for Android to implement at a later date.

@niumj
Copy link

niumj commented Aug 16, 2023

@jsharp83
Add webkit interface for showing javascript alert message

Thank you for your contents. But when I add the changes to [webview_flutter_wkwebview] , the below errors
FWFWKJavaScriptPanelType Expected a type
Unknown type name 'FWFWKJavaScriptPanelCompletionData'
Use of undeclared identifier 'FWFWKJavaScriptPanel'

FWFWKJavaScriptPanelCompletionData Expected ')'

What can I do? or can you upload other neccessary files?

@jsharp83
Copy link
Contributor Author

@niumj

It is defined in
packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart

You should run pigeon script on webview_flutter_wkwebview folder

flutter pub run pigeon --input pigeons/web_kit.dart

I closed this PR because I uploaded a new PR with Android version implementation.

If you just add a feature temporary in iOS, check this commit
main...jsharp83:packages:temp-add-javascript-system-popup

@niumj
Copy link

niumj commented Aug 18, 2023

@jsharp83
Thank you for your attention.
But when I use it, system popup is working, the below error is also happened.

  • [[FWFUIDelegate webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:] was called more than once']

After that the app is exited.
How can I do or any suggestions?

auto-submit bot pushed a commit that referenced this pull request Feb 9, 2024
…#4704)

* there are cases where Web calls System Popup with javascript on webview_flutter
* At this time, the message comes in the WKUIDelegate part in iOS.
   * https://developer.apple.com/documentation/webkit/wkuidelegate/1537406-webview
   * https://developer.apple.com/documentation/webkit/wkuidelegate/1536489-webview
* Android also has a interface on WebChromeClient
   * https://developer.android.com/reference/android/webkit/WebChromeClient#onJsAlert(android.webkit.WebView,%20java.lang.String,%20java.lang.String,%20android.webkit.JsResult)
* It was implemented according to the requirements of the code review of the #4555
* Related issue: flutter/flutter#30358 (comment)
* Related Interface PR: #5670
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants