正在处理在chrome扩展中不起作用的js

Processing js not working in chrome extensions

本文关键字:不起作用 js 扩展 处理 chrome      更新时间:2023-09-26

我在Google Chrome扩展中使用Processing JS。常规网页可以工作,但当我尝试扩展时,会显示以下内容:

window.localStorage is not available in packaged apps. Use chrome.storage.local instead. extensions::platformApp:17
processing.js:718 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' chrome-extension-resource:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
processing.js:798 Processing.js: Unable to execute pjs sketch.
processing.js:799 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' chrome-extension-resource:".

有办法绕过这个吗?

否。

你不能放松Chrome应用程序的默认CSP以允许eval,也不能让localStorage工作,它被禁用,chrome.storage是异步的,因此你不能进行polyfill。

除非Processing制作了一个与Chrome应用程序平台兼容的版本,或者你对它进行了大量修改,否则它是不可能解决的。