简体   繁体   English

在 Chrome 应用程序中使用 Fabric.js

[英]Using Fabric.js in a Chrome app

So, I'm building a simple video editor.所以,我正在构建一个简单的视频编辑器。 I'm using Fabric.js <script src="/js/fabric.js"></script> to manipulate the canvas on which I'm doing the editing.我正在使用 Fabric.js <script src="/js/fabric.js"></script>来操作我正在编辑的画布。

I've left out the Serialization and Parser models of it but it still uses eval for something which throws an error:我已经省略了它的序列化和解析器模型,但它仍然使用 eval 来处理抛出错误的东西:

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'self' blob: filesystem: chrome-extension-resource:".

fabric.Canvas(String id) still works but shape objects don't (eg new fabric.Rect(); throws an Uncaught TypeError: fabric.Circle is not a constructor ) fabric.Canvas(String id)仍然有效,但形状对象不起作用(例如new fabric.Rect();抛出Uncaught TypeError: fabric.Circle is not a constructor

This is my first Chrome app and I don't really understand what's happening.这是我的第一个 Chrome 应用程序,我真的不明白发生了什么。 If anyone could help me figure out how to use Fabric in this environment that would be most excellent.如果有人能帮我弄清楚如何在这种环境中使用 Fabric 那就最好了。

Thanks in advance.提前致谢。

The fact that Fabric is not 'unsafe-eval' CSP-compliant is a known issue . Fabric 不符合'unsafe-eval' CSP 的事实是一个已知问题

As such, the only way to use it in an app or an extension is to sandbox it: perform all operations in a frame loaded as sandbox, and pass data both ways with postMessage .因此,在应用程序或扩展程序中使用它的唯一方法是将其沙箱化:在作为沙箱加载的框架中执行所有操作,并使用postMessage双向传递数据。

See the documentation article "Using eval in Chrome Extensions. Safely."请参阅文档文章“在 Chrome 扩展程序中使用 eval。安全”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM