实时代码编辑器 Codemirror - 实时预览无法执行

Live Code Editor Codemirror - Live Preview Won't Execute

我正在开发一个具有实时预览功能的代码编辑器(如 jsbin),我可以在我的 chrome 书籍上离线使用。

然而,当我在浏览器中加载它时,实时预览工作正常,但作为 chrome 应用程序,它不会更新 iframe。您可以在 Github.

上查看源代码

有谁知道原因和解决方法吗?

这是在扩展的开发者控制台中显示的内容。

unload is not available in packaged apps.___________________________extensions::platformApp:17  
document.open() is not available in packaged apps.__________________extensions::platformApp:17   
Uncaught Error: document.write() is not available in packaged apps.    ____extensions::platformApp:31 

这就是问题...

function updatePreview() {
  var previewFrame = document.getElementById("preview");
  var preview =  previewFrame.contentDocument ||  previewFrame.contentWindow.document;
  preview.open();
  preview.write('<style type="text/css">' + cssEditor.getValue() + '</style>'); 
  preview.write(htmlEditor.getValue());
  preview.close();
}

措辞上的错误很明显。

Chrome 应用程序平台禁用了许多 Web API。

Though Chrome Apps use the web platform, some web features have been disabled or else are used in a different way. Mainly this is to avoid security issues and to improve programming practices.

完整列表可在 Disabled Web Features 文档中找到,并提供解决方法建议。

您需要调整代码以适应 Chrome Apps 平台;没有万能的妙方。