capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

feat: Capacitor in iframes

Open systemlord01 opened this issue 3 years ago • 2 comments

Feature Request

Capacitor in iframes

Description

Make Capacitor available in iframes. Now we cannot use the plugins and other functions inside iframes.

Platform(s)

ios

Preferred Solution

As seen in the code here the userscripts are only executed for the mainFame. So setting this to false would make the plugins available available in the iframes.

forMainFrameOnly: true

Alternatives

I see no other solution

Additional Context

Our application running in the main frame is only for navigating between apps opened in iframes. These apps are the ones using capacitor. But plugins are unavailable as we said before. Also window.webkit is not available in iframes making capacitor think it is on the 'web' platform.

I would think capacitor capabilities and plugins should be available in all the frames.

systemlord01 avatar Jan 13 '23 15:01 systemlord01

I am in the exact same situation. Are there any workarounds?

euregon avatar Feb 12 '25 14:02 euregon

Solution 1

I m tried copying the window.capacitor object to the child frame window.

I think you can then use the capacitor stuff by accessing it through window.capacitor (so you can not use the libraries and the typings they provide although you can also work around that.

Solution 2 (can work on different domains if you set all the sandboxing permissions right)

If your Iframes have enough permissions. You could use postmessage to communicate between frames.

You could generate a lib with the same API that postmessages your method calls (instead of sending it to capacitor send it to the parent frame who executes it in capacitor).

systemlord01 avatar Feb 13 '25 18:02 systemlord01