Blocked a frame with origin “ionic://” from accessing a cross-origin frame

I’m trying to access an iframe in an ionic android app, but am getting the following error:

Blocked a frame with origin "ionic://" from accessing a cross-origin frame

when I try to access iframe.contentWindow.

I know that it arises from the cross origin security issue, but I need to find a way to be able to access the content inside the iframe in an android app.

Any ideas would be welcome.

This error is not a bug. The same-origin policy is a security mechanism that ensures that window objects only have access to the informations they are authorized to get.

The window.postMessage() method provides a controlled mechanism to securely circumvent this Same-Origin Policy restriction. The window.postMessage() safely enables cross-origin communication between Window objects; e.g: between a page and an iframe embedded within it.

postMessage(message, targetOrigin)
postMessage(message, targetOrigin, [transfer])

targetOrigin - specifies what the origin of targetWindow must be for the event to be dispatched, either as the literal string “*” (indicating no preference) or as a URI.