mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-09 03:07:20 +02: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 id="js-js-code" data-type="js" class="code-wrap"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="demo-side" id="js-demo-side">
|
<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>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"storage"
|
"storage"
|
||||||
],
|
],
|
||||||
|
"content_security_policy": "script-src 'self' 'unsafe-eval' 'sha256-oEJh/gQdHXu0Vw34Jd7uSMA+d9M2HnPWjJvHIqRgs0w='; object-src 'self'",
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "icon-16.png"
|
"16": "icon-16.png"
|
||||||
}
|
}
|
||||||
|
24
script.js
24
script.js
@ -80,23 +80,19 @@
|
|||||||
var css = editur.cm.css.getValue();
|
var css = editur.cm.css.getValue();
|
||||||
var js = editur.cm.js.getValue();
|
var js = editur.cm.js.getValue();
|
||||||
|
|
||||||
self.demoFrameDocument.open(html);
|
frame.contentWindow.location.reload();
|
||||||
|
|
||||||
|
// 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.write(html);
|
||||||
self.demoFrameDocument.close();
|
self.demoFrameDocument.close();
|
||||||
|
|
||||||
var scriptTag = document.createElement('script');
|
frame.contentWindow.postMessage(js, '*')
|
||||||
scriptTag.textContent = js;
|
},0);
|
||||||
self.demoFrameDocument.body.appendChild(scriptTag);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function initEditor(element, options) {
|
function initEditor(element, options) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user