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

Plugin crashes when used in Capacitor #29

Closed
HarelM opened this issue Jul 29, 2022 · 4 comments · Fixed by #30
Closed

Plugin crashes when used in Capacitor #29

HarelM opened this issue Jul 29, 2022 · 4 comments · Fixed by #30
Milestone

Comments

@HarelM
Copy link
Contributor

HarelM commented Jul 29, 2022

Hi,

I'm migrating to capacitor but haven't found a good equivalent to this plugin there.
Unfortunately this plugin crashes in Capacitor environment as can be read in the following bug I opened there:
ionic-team/capacitor#5811

Is there a different way this plugin could send the message without using the webview engine? Maybe some "regular" plugin event that one would register in the js code?
It will be more specific to this plugin, but more readable if one reads the code as it's not a "weird" regular javascript message but rather a plugin callback which is "obvious" that it is part of the plugin API.

If this is something that might interest you, I might be able to send a PR...

@HarelM HarelM changed the title Plugin crashes when used in Capasitor Plugin crashes when used in Capacitor Jul 29, 2022
@dpogue
Copy link
Member

dpogue commented Jul 29, 2022

It looks like this.webView.sendJavascript(String js) might work in this case (and seems to be supported by Capacitor), since we're passing null for the callback.

Cordova says it's deprecated because it doesn't properly use a bi-directional bridge, but we're just firing an event so that's probably fine for this use case.

@HarelM
Copy link
Contributor Author

HarelM commented Jul 29, 2022

Wow, thanks for the super fast response!
Yes, you are right, this does work although marked as deprecated.
Let me know how you would like to proceed.
Check for null and fallback to sendJavasript? wait to see if ionic's team answers?

This does work in iOS so I believe they have implemented something there that will allow running javascript, so it feels like a missing implementation in android rather than something that is on purpose...

@dpogue
Copy link
Member

dpogue commented Jul 29, 2022

Checking for null and falling back is probably the safest option. Would protect us if Cordova ever decides to drop the deprecated API.

I'm curious to hear what the Capacitor team replies, but it would be nice to be compatible with existing versions of Capacitor.

@HarelM
Copy link
Contributor Author

HarelM commented Jul 30, 2022

I've opened a PR for the fix.
From the short test I did it looks like it's working.

@dpogue dpogue added this to the v4.0.1 milestone Sep 13, 2022
dpogue pushed a commit that referenced this issue Sep 13, 2022
Fix Capacitor issue when engine is null. Fixes #29.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants