How to solve 'x-frame-options' to 'sameorigin' in ionic4 for Iframe?

I am trying to use some URL in Iframe, But when i try to embed that Iframe in Ionic4 app, i got this error.

Refused to display ‘https://twitter.com/afdonews’ in a frame because it set ‘X-Frame-Options’ to ‘sameorigin’.

My code for Iframe is

<iframe width="100%" height="100%" src="https://twitter.com/afdonews" scrolling="no" style="border: 0;" (load)="hideLoading()">
</iframe>

can you help me in this please?

1 Like

Hi @nadeemmdsol

managed to solve? I have the same problem.

Hi, did you find the solution?? i´m dealing with the same problem

Have you try with sanitize?
Create a pipe

ng generate pipe safe

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';

@Pipe({
  name: 'safe'
})
export class SafePipe implements PipeTransform {

  constructor(protected sanitizer: DomSanitizer) {}
 
 public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
    switch (type) {
			case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
			case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
			case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
			case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
			case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
			default: throw new Error(`Invalid safe type specified: ${type}`);
		}
  }
}

and use with you url

<iframe width="100%" height="100%" [src]=" 'https://twitter.com/afdonews'| safe: 'url'" scrolling="no" style="border: 0;" (load)="hideLoading()">
</iframe>

Try this.

did you try it? Does it solve your problem? I’m facing the same issue with an IFRAME and iOS

i tried this solution but doesnt work on iOS

2021-01-28 18:13:11.143949+0100 Test App[675:245484] [Process] 0x104023418 - [pageProxyID=6, webPageID=7, PID=677] WebPageProxy::didFailProvisionalLoadForFrame: frameID = 43, domain = NSURLErrorDomain, code = -999