0

I am making an internal tool for to modify an iframe but chrome throw an error.

This is my html:

<iframe src="https://sportmaniacs.com/es/services/inscription/mitja-marato--10k-ciutat-de-tarragona-2019/5d63d5fc-bb64-4c09-98d6-7440ac1f1c51"
    frameborder="0"
></iframe>

This is my js:

  const iframe =  this.iframe.nativeElement
  if ( (iframe.contentDocument || iframe.contentWindow.document).readyState === 'complete' ) {
    iframe.onload = this.onIframeLoad.bind(this)
  } else {
    if (iframe.addEventListener) {
      iframe.addEventListener('load', this.onIframeLoad.bind(this), true)
    } else if (iframe.attachEvent) {
      iframe.attachEvent('onload', this.onIframeLoad.bind(this))
    }
  }

  function onIframeLoad() {
    const base64String = this.iframe.nativeElement.contentWindow.document.body.innerHTML
    console.log(this.iframe.nativeElement.contentWindow.document.body.children[1].currentSrc)
    console.log(base64String)
  }

But this code: iframe.contentWindow.document

Thow this error: Blocked a frame with origin "http://localhost:5200" from accessing a cross-origin frame

Could I skip the error someway? perhaps with a plugin or something...

srhuevo
  • 134
  • 8
  • 1
    This is a basic security feature. To access a cross-origin iframe, the serveur must set headers to allow you to do so. If your not the owner of the website, you cannot do much about it. – Lorenz Meyer Nov 14 '19 at 11:58
  • yes, I know. But this is an internal tool for workers team, I am sure that this could doing with an extension, supress secure of chrome or with other browser.... – srhuevo Nov 14 '19 at 12:27
  • 1
    You could proxy their site through your own and the required headers on your server – Lorenz Meyer Nov 14 '19 at 12:43

1 Answers1

0

Workaround has been described here: SecurityError: Blocked a frame with origin from accessing a cross-origin frame

It only works if you own both websites.

Otherwise you can disable the same-origin-policy in your browser, but like it says, it will only affect your browser.

Niklas
  • 16