如何使用chrome扩展名阻止特定网站上的url:我写了一些小的扩展名来阻止URL。但我希望它仅在特定网站上阻止这些URL。manifest.json
{
"name": "vidstreamBlocker",
"version": "1.0",
"description": "Chrome URL Blocking Extension",
"permissions": ["webRequest", "webRequestBlocking", "<all_urls>","activeTab"],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js
chrome.webRequest.onBeforeRequest.addListener(
info => {
const host = (info.initiator || '').split('/', 3)[2];
if (host === 'example.com') {
return {cancel: true};
}
},
{urls:
["*://*.ad-delivery.net/*"]
},
["blocking"]
);
我知道background.js持续运行,但是我只想在特定网站上阻止它们
检查initiator
属性(更多信息):
chrome.webRequest.onBeforeRequest.addListener(
info => {
const host = (info.initiator || '').split('/', 3)[2];
if (host === 'www.example.com') {
return {cancel: true};
}
},
{
urls: [
'*://*.eikegolehem.com/*',
'*://*.inpagepush.com/*',
],
},
['blocking']
);
PS您可以<all_urls>
使用主要网站和资源的模式替换manifest.json中的内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句