javascript - 关闭开发模式和 Chrome 打包应用程序 -- "document.write() is not available in the sandbox of packaged apps"

标签 javascript google-chrome-extension google-closure-library

我在 Closure 的开发模式下遇到了问题,因为我的 Chrome 打包应用程序(即 v2 list 文件)的安全策略限制了 Closure 引导过程中调用的内容(例如,当我使用未编译的应用程序加载应用程序时)开发代码时,我得到“document.write() 在打包应用程序的沙箱中不可用”)。

最佳答案

以下代码是我最终使用的代码,它非常适合在 Chrome 的打包应用框架内以开发模式运行 Closure。

在closure/goog/base.js中,覆盖goog.global.CLOSURE_IMPORT_SCRIPT,如下所示:

goog.global.CLOSURE_IMPORT_SCRIPT = function(src) {
  var script = document.createElement('script');
  script.src = src;
  script.type = 'text/javascript';
  goog.global.document.getElementsByTagName("head")[0].appendChild(script);
  return true;
};

关于javascript - 关闭开发模式和 Chrome 打包应用程序 -- "document.write() is not available in the sandbox of packaged apps",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15279728/

相关文章:

javascript - 为什么这段 JavaScript 代码中的数组没有发生变化?

javascript - 为什么应用 JSON.stringify 会占用这么多内存?

javascript - 序列化多个重复项的数组

javascript - 在 Chrome 扩展中启用/禁用 "content_scripts.css"

javascript - 使用 goog.events.listen 传递参数

angularjs - Karma 测试运行器和闭包库 "NOT SERVED FILE"

google-closure - 如何在本地托管 google libphonenumber?

javascript - 为什么我在抓取时会得到重复的数据?

javascript - 同步 Javascript 注入(inject)的 For 循环

javascript - Firefox Extension util/match-pattern 子目录