mirror of
https://github.com/chinchang/web-maker.git
synced 2025-02-20 13:16:43 +01:00
fix script execution with new CSP.
This commit is contained in:
parent
89d0b15bc2
commit
1d39b5855a
@ -208,7 +208,7 @@
|
||||
<div id="js-js-code" data-type="js" class="code-wrap"></div>
|
||||
</div>
|
||||
<div class="demo-side" id="js-demo-side">
|
||||
<iframe src="" frameborder="0" id="demo-frame"></iframe>
|
||||
<iframe src="about://blank" frameborder="0" id="demo-frame"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
|
@ -9,6 +9,7 @@
|
||||
"permissions": [
|
||||
"storage"
|
||||
],
|
||||
"content_security_policy": "script-src 'self' 'unsafe-eval' 'sha256-oEJh/gQdHXu0Vw34Jd7uSMA+d9M2HnPWjJvHIqRgs0w='; object-src 'self'",
|
||||
"icons": {
|
||||
"16": "icon-16.png"
|
||||
}
|
||||
|
26
script.js
26
script.js
@ -80,23 +80,19 @@
|
||||
var css = editur.cm.css.getValue();
|
||||
var js = editur.cm.js.getValue();
|
||||
|
||||
self.demoFrameDocument.open(html);
|
||||
self.demoFrameDocument.write(html);
|
||||
self.demoFrameDocument.close();
|
||||
frame.contentWindow.location.reload();
|
||||
|
||||
var scriptTag = document.createElement('script');
|
||||
scriptTag.textContent = js;
|
||||
self.demoFrameDocument.body.appendChild(scriptTag);
|
||||
// Do everything in next stack so that reload completes. Otherwise
|
||||
// the document context persists even after reload.
|
||||
setTimeout(function () {
|
||||
self.demoFrameDocument = frame.contentDocument;
|
||||
html = '<html><head><script>' + 'window.addEventListener("message",function (e){ window.eval(e.data);});' + '</script><style>' + css + '</style></head><body>' + html + '</body></html>';
|
||||
self.demoFrameDocument.open('text/html', 'replace');
|
||||
self.demoFrameDocument.write(html);
|
||||
self.demoFrameDocument.close();
|
||||
|
||||
var styleTag = self.demoFrameDocument.head.children.namedItem('css');
|
||||
if (styleTag) {
|
||||
styleTag.textContent = content;
|
||||
}
|
||||
else {
|
||||
styleTag = document.createElement('style');
|
||||
styleTag.textContent = css;
|
||||
self.demoFrameDocument.head.appendChild(styleTag);
|
||||
}
|
||||
frame.contentWindow.postMessage(js, '*')
|
||||
},0);
|
||||
};
|
||||
|
||||
function initEditor(element, options) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user