在我的简单gmail chrome扩展程序中 - 我想阻止在已发送的邮件中加载图像。
当我加入
时,chrome.webRequest.onBeforeRequest.addListener
内部正常工作
urls: [ "*://*.googleusercontent.com/*" ]
在urls数组中。但是这将触发我只想为此模式"*://*/#https://mysite/*",
但它根本没有触发 - 如果我包含 googleusercontent 网址,则它正在以这种格式使用details.url -
https://ci6.googleusercontent.com/proxy/IB4W2KvisZjL2rgC....#https://mysite/*
清单
"permissions": [
"webRequest",
"webRequestBlocking",
"*://*.googleusercontent.com/*",
"*://*/#https://track1/*",
"*://*.googleusercontent.com/*/://track1/*"
],
并在后台脚本
中chrome.webRequest.onBeforeRequest.addListener(
function(details) {
console.log(details);
}, {
urls: [
"*://*/#https://track1/*",
]
}, ['blocking']
);
我认为问题在于模式匹配,但我无法理解使用哪种模式
答案 0 :(得分:1)
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
// Here inside details.url - you see each image is in format https://googlecontent
console.log(details);
}, {
urls: [
"*://*/#https://track1/*",
]
}, ['blocking']
);
如上所述,在details.url中-您看到的每个图片的格式均为https://googlecontent
因此,您需要在urls
数组中包含此模式。
现在,如何获取所需的网址链接是
if (details.url.includes('<include link string here>') || details.url.includes('<other link here>')) {
if (some condition to stop image load met) cancel = true;
}