I can’t overcome this issue. Can someone give some advice?
-
I have this application that uses ExtJS library that I will need to run in Chrome extension. I have successfully created my messaging bridge (
postMessage), and sandboxed the whole application in it, and everything works as usual. ExtJS loaded, application is running. -
Then I have this piece of logic where I need to preview a piece of HTML snippets in my ExtJS viewport. I created an
iframein thePanelitself and onafterrenderI tried to write the snippet in it. This is the code I use:html: '<iframe src="about:blank" style="width:100%;height:100%;border:none;"></iframe>'; ...... //p is the panel found in afterrender p.body.down('iframe').dom.contentDocument.write(content);Then the error:
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL chrome-extension://fcnpmlgapilgclcelfanblpbglmkghbc/core/themes/default/app.html. Domains, protocols and ports must match.
-
I have tried withThis is the only way and it works. See my answer below.postMessagewithin sandbox to this dynamic iframe but nothing happens. Setting thesandboxattribute in manifest doesn’t work either.
Question:
- How should one set the manifest to support this kind of use case?
- Or is there any better way to preview HTML snippet without using an
iframe? Afaik previewing withiframeis the best as it sandboxed the snippet without being messed with parent css.
Note
This piece of code was working fine in manifest v1 but I planned to migrate it to manifest v2. I didn’t realize Content Security Policy (CSP) has became that strict.
A screen to describe the problem 😉

Sorry, this is awkward. Apparently
postMessageis the only way, and I can’t manage to get it work previously because my iframe is not loaded yet. Also, accessing the dom document in the iframe is a big no under CSP, but it’s possible to accesscontentWindowto do apostMessage.This is what I did to solve this issue. Hope someone would benefit from this:
Create a
preview.htmlin your extension rootUnder
manifest.json, add it as part of thesandboxattributeInside the
preview.html, add the following code. Note that my snippet is a full html, so I useddocument.writeinstead.Create the iframe in your code as usual, point it to your
preview.html, and attach it to the parent div orExt.Panel.Use the following code to
postMessageafter the element has been drawn/created/appended.Enjoy 😉
Edit
As pointed by Mike in Chromium forum, this issue can be solved by
srcdocas well. Simply set the iframe’s srcdoc and problem is solved.Just not sure of the status of
srcdoc