oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
138 stars 120 forks source link

Is it possible to add this functionality for iframes too? #73

Closed evo-dh closed 3 years ago

evo-dh commented 3 years ago

I want to access elements of our website that is embedded in a iframe of our ios App. It has the same problem as file access. SecurityError: Blocked a frame with origin "file://" from accessing a cross origin frame...

Is it possible to add the functionality of this plugin for iframes? The only other solution is to set-up a web server locally. Like here: https://stackoverflow.com/questions/59158823/unable-to-post-message-to-file-recipient-has-origin-null-on-cordova-wkwebvi But this solution is not great.

manish2788 commented 3 years ago

@evo-dh This plugin right now doesn't support to extend the solution to iframes.

agilethomas commented 1 year ago

In case anyone else stumbles upon this issue and wants this plugin to work in an iframe, here's how I did it.

In our case, the iframe was simply another html file in the www/ directory, but both the main app and the iframe make AJAX requests to our server. The iframe was not using the plugin but making direct requests and that didn't work (didn't have the cookies, was using CORS).

The solution turned out to be simple in our case. In the iframe, we just make sure to reference the XMLHttpRequest object that this plugin polyfills.

window.XMLHttpRequest = window.parent.XMLHttpRequest;