electron - 如何在 Electron 应用程序中包含模板组件的分布

标签 electron content-security-policy stenciljs

我真的无法在项目中包含模板分布的分布。由于 Electron 是 headless Chrome ,是否应该将其作为脚本包含在内?

我似乎有关于安全策略的错误

模板版本:
1.12.2

它们在standalone-html中运行良好

index-64aa1cf6.js:2443 Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-imoMl/F66ZbGZfn+J0jtlxdZvr/1ZBs+8ReasI4LBKQ='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.

bootstrapLazy @ index-64aa1cf6.js:2443
index-64aa1cf6.js:2888 Refused to load the script 'blob:file:///f7aff0d4-a09c-464c-8344-451ac3a43fba' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

最佳答案

Electron 不是 headless Chrome ,它基于 Chrome 。

您的错误消息告诉您已启用 CSP(内容安全策略),因此加载脚本和内联样式已被阻止。

您可以更改 CSP 规则以允许加载该脚本,或者禁用 CSP(不太安全)。

链接:

  • https://github.com/electron/electron/blob/master/docs/tutorial/security.md#6-define-a-content-security-policy
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP

  • 问题也可能只是您试图将脚本包含在 blob:file:// 中。协议(protocol)。

    对于阻塞的内联样式,您可以在指令中添加随机数或哈希源(更安全),或使用 'unsafe-inline' .

    关于electron - 如何在 Electron 应用程序中包含模板组件的分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61506122/

    相关文章:

    electron - 在 Electron 生成器自定义NSIS包含脚本中的哪里可以看到回声的输出?

    android - Cordova 的内容安全策略未加载外部脚本和样式表(404 错误)

    ionic-framework - Stenciljs - 背景图片 css 路径

    javascript - 嵌套 Web 组件并将其与常规 HTML 混合

    javascript - Electron :加载外部脚本并将其传递给函数

    node.js - Reactjs + Electron + Nodejs

    node.js - 触摸板捏合缩放在 Electron (MacOS) 中不起作用

    google-chrome - 为什么 Chrome 不尊重我的内容安全策略哈希?

    ios - 内容安全策略框架祖先。 Iframe 不会在 iOS10 中加载内容

    javascript - Ionic4 组件 - 菜单 : must have a 'content' element to listen for drag events on