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

bug: OAuth Cordova plugin crashes on android due to missing getEngine implementation #5811

Closed
HarelM opened this issue Jul 29, 2022 · 2 comments

Comments

@HarelM
Copy link

HarelM commented Jul 29, 2022

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 4.0.1
  @capacitor/core: 4.0.1
  @capacitor/android: 4.0.1
  @capacitor/ios: 4.0.1

Installed Dependencies:

  @capacitor/cli: 3.6.0
  @capacitor/core: 3.6.0
  @capacitor/android: 3.6.0
  @capacitor/ios: 3.6.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Affects only android as far as I know

Current Behavior

When a plugin would like to evaluate a js code and run it in the webview this will crash android app in capacitor.

Expected Behavior

Cordova plugin should work without crashes, or there should be an equivalent plugin I could use

Code Reproduction

Basically use a cordova plugin with the following line in android:
this.webView.getEngine().evaluateJavascript("window.dispatchEvent(new MessageEvent('message', { data: 'data' }));", null);
This code can be found here:
https://github.com/AyogoHealth/cordova-plugin-oauth/blob/a09b837cefb1f17628eef1d6d8dba88877149383/src/android/OAuthPlugin.java#L124

Other Technical Details

npm --version output: 8.1.2

node --version output: v16.13.2

pod --version output (iOS issues only): 1.11.3

Additional Context

I can see the the mock codorva webview implementation returns null when one request the engine in order to evaluate js code.
I guess one could only implement this method at this point in time in order to allow plugins to be able to evaluate js when they run in capacitor environment.
See here:

Let me know if this is something that you would like to add to the mock and I might be able to send a PR.

@jcesarmobile
Copy link
Member

jcesarmobile commented Aug 1, 2022

This is a duplicate of #5390
It says webView.engine because that particular plugin uses kotlin, but the problem is the same.

As workaround if the plugin is yours or you want to fork it, the code can be changed to something like:

WebView webViewImpl;
if(this.webView.getEngine() != null){
    webViewImpl = ((WebView) this.webView.getEngine().getView());
}
else {
    webViewImpl = (WebView) this.webView.getView();
}
webViewImpl.evaluateJavascript("window.dispatchEvent(new MessageEvent('message', { data: 'data' }));", null);

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2022
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants