Sun, 18 Oct 2020 08:29:03 GMT
Join the conversation at slack.cordova.io
Sat, 17 Oct 2020 17:54:58 GMT
@slack.cordova.io-acco says
in the latest cordova, on iOS, is there a way to serve index.html, browse to an external site (under complete control), and go back to the in app content?
Sat, 17 Oct 2020 17:59:44 GMT
@norman137 says
Sounds like you want to use the inappbrowser plugin.
Sat, 17 Oct 2020 18:22:15 GMT
@slack.cordova.io-acco says
@norman137 i tried the inappbrowser plugin – it loads the external url fine, but ran into an issue trying to get the user back to the local file without the user having to click the back link on the top left corner
Sat, 17 Oct 2020 18:22:42 GMT
@slack.cordova.io-acco says
none of the event listeners triggered when the browser redirected, for example
Sat, 17 Oct 2020 18:24:11 GMT
@slack.cordova.io-acco says
i swapped out inappbrowser with plain old iframe and window messaging, but having issues with content-security-policy frame-src -
Sat, 17 Oct 2020 18:24:52 GMT
@slack.cordova.io-acco says
“Refused to load https://example.org because it does not appear in the frame-ancestors directive of the Content Security Policy.”
Sat, 17 Oct 2020 18:25:34 GMT
@slack.cordova.io-acco says
which is strange since the “https://example.org” response has a header “Content-Security-Policy default-src * ‘unsafe-eval’ ‘unsafe-inline’ data: filesystem: about: blob: ws: wss:; frame-ancestors * ‘unsafe-eval’ ‘unsafe-inline’ data: filesystem: blob: ws: wss:;”
Sat, 17 Oct 2020 18:37:19 GMT
@norman137 says
it‘s not the iframe page that needs to send that header, it’s the “webserver” that serves the page with the iframe that needs to. The problem is there is no webserver in the cordova context, so afaik that CSP policy header cannot be done. That issue is documented at https://github.com/apache/cordova-android/issues/560
For security reasons if you‘re loading an external website, it should be done in an inappbrowser, but that’s not something I have ever used in my apps so I don't really know too much on the plugin. But i do believe there is a way for the main webview and the inappbrowser webview to communicate via
webkit.messageHandlers.cordova_iab.postMessage
? Pretty sure that can be used to signal the main webview by listening to themessage
event when to close the inappbrowser
Sat, 17 Oct 2020 18:40:12 GMT
@slack.cordova.io-acco says
yep, tried the webkit.messageHandlers, which seems to be available when the execute script method is run on the inappbrowser... the main issue i had with that was with the timing of it, e.g. to know when to execute the script since none of the inappbrowser event listeners triggered any of the advertised events
Sat, 17 Oct 2020 18:40:29 GMT
@slack.cordova.io-acco says
i'll try that again though, and keep polling with the executescript to see if i can at least send a message
Sat, 17 Oct 2020 18:40:37 GMT
@slack.cordova.io-acco says
will update here shortly
Sat, 17 Oct 2020 19:08:06 GMT
@slack.cordova.io-acco says
let inAppBrowserReference = window.cordova.InAppBrowser.open(ref, '_system', 'location=no,hardwareback=no,toolbar=no,hidden=yes,beforeload=yes'); window.seebappbrowser = inAppBrowserReference; let events = ['loadstart','loadstop','loaderror', 'exit','beforeload','message']; for (let eventKey in events) { let event = events[eventKey]; console.log("Adding in app browser event listener for ", event) inAppBrowserReference.addEventListener(event, function(params) { console.log("Got an event: ", params); if (!!params && !!params.url) { } }); } let pollerHandler = function(params) { console.log("In Poller Handler, received: ", params); if (!!params) { console.log("params are: ", JSON.stringify(params)); } } let poller = function() { console.log("calling executescript on in app browser reference:"); inAppBrowserReference.executeScript({ code: "\ var message = window.location.href;\ var messageObj = {location: message};\ console.log('hello from the insde; ' + window.location.href)\ var stringifiedMessageObj = JSON.stringify(messageObj);\ webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);" }, pollerHandler, pollerHandler); } setInterval(poller, 500); inAppBrowserReference.show();```
Sat, 17 Oct 2020 19:08:32 GMT
@slack.cordova.io-acco says
it looks like nothing is getting back to the window serving the local file
Sat, 17 Oct 2020 19:08:58 GMT
@slack.cordova.io-acco says
tried setting the event handler for the “message” event type as well as specifying a callback on the executescript method
Sat, 17 Oct 2020 19:11:54 GMT
@slack.cordova.io-acco says
and the “message” and “loadstop” etc. events have the handler as numHandlers=1
Sat, 17 Oct 2020 19:15:10 GMT
@slack.cordova.io-acco says
doh, “(Only available when the target is set to
'_blank'
)”
Sat, 17 Oct 2020 19:15:20 GMT
@slack.cordova.io-acco says
trying that now
Sat, 17 Oct 2020 19:21:39 GMT
@slack.cordova.io-acco says
it worked, yay
Sat, 17 Oct 2020 19:22:02 GMT
@slack.cordova.io-acco says
thanks @norman137
Sat, 17 Oct 2020 19:22:15 GMT
@norman137 says
np, glad I could help.
Sat, 17 Oct 2020 19:51:31 GMT
@slack.cordova.io-acco says
@slack.cordova.io-acco has left the channel