I'm having issues retrieving elements inside on an iFrame. Let's spend first two words about how the site is structured (don't ask me why in that way lol):
- There is the main website, let's call it website A;
- Inside website A, there is a iFrame, which is an entire another project, let's call it website B;
- Inside website B, there is a specific section which have another iFrame, which will show slideshows, hosted on an s3 bucket.. inside an iFrame;
Summary, there is an Amazon S3 bucket content (html) shown in iFrame inside website B, which is an iFrame of website A.
Now, I want to access to elements inside the inner html, the one showed through a public s3 bucket inside the inner iFrame. I'm using angular 8 with TypeScript, I'm able to get the iFrame as native element, but I'm not able to access contentDocument. This is how the code looks like of the component of website B which have the tag on its html:
@ViewChild('iframe', { read: ElementRef, static: true }) iframe: ElementRef;
ngAfterViewInit() {
this.iframe.nativeElement.onload = () => {
this.intervalSubscription = timer(1000, 250).subscribe(() => {
console.log(this.iframe.nativeElement.contentDocument);
if(this.iframe.nativeElement.contentDocument != null){
const doc: HTMLDocument = this.iframe.nativeElement.contentDocument || this.iframe.nativeElement.contentWindow.document;
let nextButton: HTMLElement;
['.component_base.next', '.universal-control-panel__button_next', '.uikit-primary-button_next', '#next'].some(selector => {
nextButton = doc.querySelector(selector) as HTMLElement;
return !!nextButton;
});
if (nextButton && (nextButton.hasAttribute('disabled') || nextButton.style.display === 'none')) {
this.slideshowCompleted.emit(true);
this.intervalSubscription.unsubscribe();
}
}
});
};
}
I'm getting this error:
ERROR DOMException: Blocked a frame with origin "http://localhost:4400" (which is website B) from accessing a cross-origin frame.
enter image description here If I console log the contentDocument is null, even tho the html get displayed fine. I even set some cors stuffs on the bucket as chat gpt suggested me to lol but didn't worked.. any advice?? I need to have access to a specific button inside this html, because basically when it's disabled it means the user finished watching the slideshow and I'll call backend to update a value about the progress of the slideshow is done
This is what I get instead if I console.log(this.iframe.nativeElement) only: