我正在用InboxSDK开发一个运行在Gmail上的Google扩展。现在Gmail部分已经准备好了,我希望扩展到其他具有不需要InboxSDK或Gmail功能的功能子集的网站。我的想法是尝试加载InboxSDK (它检查支持的起源),如果它不加载,跳过Gmail特性。
尽管如此,我遇到了一个问题,通过调用InboxSDK.load(2, "app_id")来加载InboxSDK的时候,会在控制台中打印一条消息:InboxSDK: Unsupported origin https://stackoverflow.com,并停止执行超过此点的任何代码。
我不需要InboxSDK的起源,除了Gmail。
是否可以在Gmail上运行与InboxSDK相同的扩展,而在其他网站上不使用InboxSDK?
我提供了一个简单的TypeScript代码来说明这种情况:
import * as InboxSDK from "inboxsdk"
(async function main() {
console.log("This will print on all websites")
const sdk = await InboxSDK.load(2, "APP_ID")
console.log("This will not be printed if the InboxSDK load fails")
})()我看到的一个可能的解决方案是实现与InboxSDK相同的原产地检查。我正在寻找一个更好的解决方案,它不需要重复这个InboxSDK功能。
发布于 2020-06-22 09:45:00
不如使用不同的内容脚本来初始化gmail、url和其他代码。那么,甚至不要在不需要inboxSDK的地方加载它。应该为您提供更好的控制,并且只在需要时加载inboxSDK。这可能也会解决“不支持的起源”的问题。
"content_scripts": [
{
"matches": ["https://mail.google.com/*"],
"js": [
"libs/inboxsdk.js",
"script/my_entry_with_inboxsdk.js"
],
"runt_at": "document_end"
},
{
"matches": ["https://*.everything-but-gmail.*"],
"js": [
"script/my_entry_without_inboxsdk.js"
],
"runt_at": "document_end"
}],
https://stackoverflow.com/questions/56647211
复制相似问题