Goal: Send string variable from Angular application(typesript) to iFrame living on another server so it can be used in a conditional
Question: How do I use DomSanitizer for a variable specifically?
Documentation states types are: HTML, Style, Script, Url. What if I just want to send a plain string variable? Documentation is not clear about this.
SecurityContext shows the same https://angular.io/api/core/SecurityContext . I tried script. I also tried sanitize method but it needs securitycontext.
I tried using Script but I get the error: Error: unsafe value used in a resource URL context (see http://g.co/ng/security#xss) at DomSanitizerImpl.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DomSanitizerImpl.sanitize
I read (http://g.co/ng/security#xss) and (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#Security_concerns) as well as other articles about domsanitizer, postmessage, Angular lifecycles, etc I have tried placing the code in different areas of the file, including onload etc.
chat.component.html:
<div class="iframe-container">
<iframe id="iframe_chatui" src="{{ chatURL }}/loading.html" class="chatiframe" allow="microphone; camera"></iframe>
</div>
chat.component.ts:
ngAfterViewInit() {
this.safeScript = this.domSanitizer.bypassSecurityTrustScript(this.localeId);
let frame = document.getElementById('iframe_chatui');
}
when I add the following, I get error: Cannot read property 'contentWindow' of null
let frame = document.getElementById('iframe_chatui') as HTMLIFrameElement;
frame.contentWindow.postMessage(this.localeId, '*');