我想导入钠.js
加以在 Chrome 扩展程序的文件中使用。该库的文档仅显示了如何在带有<script>
标签的 html 文件中包含扩展名。当我这样做时,我得到一个错误:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".
.js
我尝试通过文件直接导入:
import SodiumPlus from "./sodium-plus.min.js";
(async function() {
if (!window.sodium) window.sodium = await SodiumPlus.auto();
// You can now use the sodium object here.
// Just some example code to ensure it's running:
let random = await sodium.randombytes_buf(32);
let hash = await sodium.crypto_generichash('hello world');
console.log({
'random': random.toString('hex'),
'hash': hash.toString('hex')
});
})();
但是收到一个错误:
Uncaught SyntaxError: The requested module './sodium-plus.min.js' does not provide an export named 'default'
有没有办法解决这个问题?或者,是否有类似的库更容易导入到.js
Chrome 扩展的文件中?