Safari 内容脚本注入的多个白名单/黑名单?
我正在用两个不同的内容脚本构建一个Safari扩展。一个脚本需要注入所有http页面(但不是https页面)。另一个只会被注入到google.com页面,而不考虑方案 为了实现这一点,我将扩展网站访问设置为: 这意味着在较高的级别上,我的扩展中的内容脚本应该能够访问所有页面 为了获得更细粒度的控制,我通过编程将内容脚本注入到与我的模式匹配的URL中Safari 内容脚本注入的多个白名单/黑名单?,safari,safari-extension,Safari,Safari Extension,我正在用两个不同的内容脚本构建一个Safari扩展。一个脚本需要注入所有http页面(但不是https页面)。另一个只会被注入到google.com页面,而不考虑方案 为了实现这一点,我将扩展网站访问设置为: 这意味着在较高的级别上,我的扩展中的内容脚本应该能够访问所有页面 为了获得更细粒度的控制,我通过编程将内容脚本注入到与我的模式匹配的URL中 App = { content: { // Inject into unsecure pages. whitelist: ['
App = {
content: {
// Inject into unsecure pages.
whitelist: ['http://*/*'],
// But not into secure pages.
blackList: ['https://*/*'],
loc: safari.extension.baseURI + 'data/content.js'
},
results: {
// Inject this script into all google.com pages
whiteList: ['http://*.google.com/*', 'https://*.google.com/*'],
// Surely I don't need a blacklist if I specify a whitelist?
blacklist: undefined,
loc: safari.extension.baseURI + 'data/results.js',
}
};
// Inject the first content script.
safari.extension.addContentScriptFromURL(App.content.loc,
App.content.whitelist, App.content.blacklist, false);
// Inject the second content script.
safari.extension.addContentStyleSheetFromURL(App.results.cssLoc,
App.results.whitelist, App.results.blacklist, false);
问题是这两个脚本都被注入到所有页面中。我的白名单和黑名单好像什么都没做。我做错了什么?我在顶部的whilelist/blacklist定义中使用了大写字母:
App = {
content: {
blackList: ['https://*/*'],
},
results: {
whiteList: ['http://*.google.com/*', 'https://*.google.com/*']
}
};
但是,当我将列表传递到脚本注入函数时,使用非大写版本的变量
safari.extension.addContentScriptFromURL(App.content.loc, App.content.whitelist, App.content.blacklist, false);
这显然意味着
未定义的被传递到注入函数中,而不是实际的白名单/黑名单。请使用问题的编辑链接添加其他信息。“发布答案”按钮只能用于问题的完整答案。我改进了答案并投票关闭了原始问题。我希望更改是令人满意的。我不知道这是否是问题的根源,但您不应该在第一个注入命令中同时使用白名单和黑名单,因为这两个集合完全平铺了空间。