ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.17k stars 1.01k forks source link

How to communicate between InappBrowser and my capacitor app? #2298

Closed JoshuvaGeorge03 closed 4 years ago

JoshuvaGeorge03 commented 4 years ago

I want to send message from inappbrowser back to my app.

We can do that with cordova inappbrowser plugin using postMessage. (window.parent.postMessage).

But in Capacitor Browser Plugin there is no doc for that, also there is no api to listen to that messages? So I can't able to send data back to my app also.

Current Scenario

I was hoisting my website using firebase. And I was loading that website inside of inappbrowser. And After user did some action, I want to send message to my app to run some code.

window.parent.postMessage(JSON.stringify('message', '*')

This is my code to send the message from inappbrowser to app. That is not working at all.

Expected

Kindly advice, If I am doing something wrong. And kindly tell me, how to achieve it.

Also, Kindly advice how to hide url bar in the inappbrowser?

digaus commented 4 years ago

I want to send message from inappbrowser back to my app.

We can do that with cordova inappbrowser plugin using postMessage. (window.parent.postMessage).

But in Capacitor Browser Plugin there is no doc for that, also there is no api to listen to that messages? So I can't able to send data back to my app also.

Current Scenario

I was hoisting my website using firebase. And I was loading that website inside of inappbrowser. And After user did some action, I want to send message to my app to run some code.

window.parent.postMessage(JSON.stringify('message', '*')

This is my code to send the message from inappbrowser to app. That is not working at all.

Expected

Kindly advice, If I am doing something wrong. And kindly tell me, how to achieve it.

Also, Kindly advice how to hide url bar in the inappbrowser?

This is documented in the inappbrowser plugin.

Just call browserRef.addEventListener('message', (message: any) => { console.log(message});

browserRef is the reference if the opened iab.

Everything you want to do is documented on github entry for inappbrowser. This has no place here and you should really read the documentation...

https://github.com/apache/cordova-plugin-inappbrowser/blob/master/README.md

JoshuvaGeorge03 commented 4 years ago

@digaus I am not talking about cordova-plugin-inappbrowser. I have gone through that documentation and I know how to do using cordova-plugin-inappbrowser.

I am talking about Capacitor Browser Plugin api, And I want to know how to do like that thing in this plugin?

Should we not use this plugin for inappbrowser requirements?

kindly check the link and advice. https://capacitor.ionicframework.com/docs/apis/browser

digaus commented 4 years ago

@digaus I am not talking about cordova-plugin-inappbrowser. I have gone through that documentation and I know how to do using cordova-plugin-inappbrowser.

I am talking about Capacitor Browser Plugin api, And I want to know how to do like that thing in this plugin?

Should we not use this plugin for inappbrowser requirements?

kindly check the link and advice. https://capacitor.ionicframework.com/docs/apis/browser

The capacitor browser plugin is very limited. It is only for basic usage and if you want to do more you should use the inappbrowser plugin. You can write a feature request but it would need a major rework since on android capacitor uses the Chrome Custom Tabs and these do not seem to support features needed for such a communitcation:

https://developer.chrome.com/multidevice/android/customtabs

JoshuvaGeorge03 commented 4 years ago

@digaus Thanks, will use cordova-plugin-inappbrowser.

bryplano commented 4 years ago

Sounds like this one is 👍, will close

JoshuvaGeorge03 commented 4 years ago

@digaus I have used cordova-plugin-inappbrowser and it seems to be working fine in android.

But in ios, it throws run time error. when I try to open

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1039d784c)

Kindly find the image for your reference.

image

What to do? In cordova powered apps, it seems to work.

In android, it work perfectly well even using capacitor as runtime.

digaus commented 4 years ago

@digaus I have used cordova-plugin-inappbrowser and it seems to be working fine in android.

But in ios, it throws run time error. when I try to open

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1039d784c)

Kindly find the image for your reference.

image

What to do? In cordova powered apps, it seems to work.

In android, it work perfectly well even using capacitor as runtime.

Don't know, it works for me. Maybe create an issue on inappbrowser plugin.

ionitron-bot[bot] commented 1 year ago

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.