0

I am trying to load an external webpage inside an iframe. The external webpage includes javascript and html.

When I try to load the iframe, I get the following error:

Uncaught DOMException: Blocked a frame with origin "https://www.example.com" from accessing a cross-origin frame.

Here is the content script code

let iframeEl = document.createElement('iframe');
iframeEl.src = "https://www.example.com";
document.body.appendChild(iframeEl);

How can I get past the cross origin error?

dipole_moment
  • 3,489
  • 2
  • 30
  • 48
  • Why not? Simply create an iframe element in the content script and assign its `src` property. – wOxxOm Mar 15 '17 at 00:33
  • you'll also need to inject a `content script` (with `"all_frames": true`) into the `iframe` page to do the `postMessage` stuff, but it's definitely possible to do what you need – Jaromanda X Mar 15 '17 at 00:36
  • The main issue is that when I do, I get the error "Uncaught DOMException: Blocked a frame with origin ...". Essentially, cross origin leads to failure. – dipole_moment Mar 15 '17 at 00:46
  • 1
    @dipole_moment, then show us the code and error (i.e. supply a [MCVE].) – Makyen Mar 15 '17 at 00:48
  • @wOxxOm I am getting a cross origin error. – dipole_moment Mar 15 '17 at 03:13
  • @dipole_moment, the posted code does not access the iframe so the error is caused by something else. Use the devtools debugger. – wOxxOm Mar 15 '17 at 10:00
  • You may want to check suggested workaround given in this [SO post](http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame) and see if it will help you. As mentioned, you can work on this problem using `window.postMessage` and its relative message event to send messages between the two pages. – Teyam Mar 15 '17 at 14:44
  • please see answer here: http://stackoverflow.com/questions/15532791/getting-around-x-frame-options-deny-in-a-chrome-extension/15534822#15534822 – Gabe O'Leary Apr 24 '17 at 19:16

0 Answers0