Chrome扩展清单V3不与谷歌Picker API工作



Google Chrome扩展Manifest v3不允许外部脚本&内联脚本:

在Manifest V3中,扩展的所有逻辑必须包含在扩展中。您无法再加载和执行远程托管文件。
-来源

这是manifest.json中的content_security_policy:

"content_security_policy": {
"extension_pages": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval';  style-src 'self' 'unsafe-inline'; script-src-elem 'self' 'unsafe-inline';",
"sandbox": "sandbox"
}

我一直在尝试使用Google驱动器选择器API在一个GoogleChrome扩展,但不知何故无法这样做。

库需要这两个脚本:

<script async defer src="https://apis.google.com/js/api.js" onload="onApiLoad()"></script>
<script async defer src="https://accounts.google.com/gsi/client" onload="gisLoaded()"></script>

我已经在本地下载了扩展:

<script async defer src="./lib/apis.google.com/js/api.js"></script>
<script async defer src="./lib/accounts.google.com/gsi/client.js"></script>
window.addEventListener('load', () => gapiLoaded())

然后这两个脚本依次安装其他外部脚本,这在Manifest v3中是不允许的:

错误1
  • 错误2

我尝试在一个弹出窗口和标签创建:

chrome.tabs.create({url: chrome.runtime.getURL('setup.html')})

都给出相同的错误

如何使用Google驱动器选择器API在一个GoogleChrome扩展吗?

谢谢

您需要在content_security_policy中声明https://apis.google.com/js/api.js
https://accounts.google.com/

"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'",
"sandbox": "sandbox allow-scripts; script-src 'self' 'https://apis.google.com/' 'https://accounts.google.com/'  'https://www.googleapis.com' 'https://ajax.googleapis.com'; object-src 'self'"
},

最新更新