// background.js
chrome.webRequest.onBeforeRequest.addListener(
blockDownloads,
{ urls: ["<all_urls>"], types: ["main_frame", "sub_frame"] },
["blocking"]
);
function blockDownloads(details) {
if (isDownloadRequest(details)) {
return { cancel: true };
}
}
// manifest.json
{
"manifest_version": 3,
"name": "Block Downloads",
"version": "1.0",
"description": "Block all downloads on web pages",
"permissions": ["webRequest", "webRequestBlocking", "activeTab"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"host_permissions": ["<all_urls>"]
}
Error content
Unchecked runtime.lastError: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest.
Please help me correct them
I tried to edit them to look like this
{
"name": "Download Blocker",
"version": "1.1",
"description": "Blocks file downloads (declarative approach)",
"manifest_version": 3,
"permissions": [
"declarativeNetRequest",
"webRequest" // Needed for observing requests
],
"background": {
"service_worker": "background.js"
},
"declarativeNetRequest": {
"rules": [
{
"id": "blockDownloads",
"priority": 1,
"condition": {
"url": {
"pathSuffix": ".pdf" // Assuming you want to block PDFs
},
"types": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xhr", "ping", "other"] // Block all request types
},
"action": {
"type": "cancel"
}
}
]
}
}
however there was an error
Unrecognized manifest key ‘declarativeNetRequest’.
Please help me correct them