Open greygoody opened 5 months ago
webRequestBlocking
requires manifest version of 2 or lower.Chrome Manifest V3 does not support the webRequestBlocking
permission. Instead, you should use the declarativeNetRequest
API, which provides similar functionality. You need to update the permissions and make necessary changes in your code to accommodate this new API.
Replace webRequest
and webRequestBlocking
permissions with declarativeNetRequest
:
{
"update_url": "https://clients2.google.com/service/update2/crx",
"manifest_version": 3,
"minimum_chrome_version": "88.0",
"name": "XDM Browser Monitor",
"description": "XDM integration module for Firefox and Chromium based browsers",
"version": "2.0",
"icons": {
"48": "icon.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs",
"cookies",
"contextMenus",
"activeTab",
"declarativeNetRequest"
],
"host_permissions": [
"http://*/*",
"https://*/*"
],
"commands": {
"toggle-monitoring": {
"suggested_key": {
"default": "Ctrl+Shift+E",
"mac": "Command+Shift+E"
},
"description": "Toggle monitoring"
}
}
}
background.js
:Replace webRequest
listeners with declarativeNetRequest
rules.
chrome.runtime.onInstalled.addListener(() => {
// Define the rules for blocking requests
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [1],
addRules: [
{
id: 1,
priority: 1,
action: { type: "block" },
condition: {
urlFilter: "*",
resourceTypes: ["main_frame", "sub_frame"]
}
}
]
});
// Set up context menus
chrome.contextMenus.create({
id: "sendImageToXDM",
title: "Send Image to XDM",
contexts: ["image"]
});
chrome.contextMenus.create({
id: "sendLinkToXDM",
title: "Send Link to XDM",
contexts: ["link", "video", "audio"]
});
chrome.contextMenus.create({
id: "runContentScript",
title: "Run Content Script",
contexts: ["all"]
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case "sendImageToXDM":
sendImageToXDM(info, tab);
break;
case "sendLinkToXDM":
sendLinkToXDM(info, tab);
break;
case "runContentScript":
runContentScript(info, tab);
break;
}
});
// Rest of the functions go here...
webRequestBlocking
permission issue.This issue will be resolved by switching to declarativeNetRequest
as shown above.
Unchecked runtime.lastError: Extensions using event pages or Service Workers must pass an id parameter to chrome.contextMenus.create
.This is fixed in the updated background.js
by adding id
parameters to chrome.contextMenus.create
.
Uncaught (in promise) Error: Failed to set icon 'icon48.png': Failed to fetch
.Ensure the icon paths are correct and the files exist. It appears there might be an issue with the paths or the files themselves. Verify that icon16.png
, icon48.png
, and icon128.png
are located in the correct directory and are named correctly.
If the files are in the same directory as manifest.json
, your manifest should have:
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"action": {
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
}
{
"update_url": "https://clients2.google.com/service/update2/crx",
"manifest_version": 3,
"minimum_chrome_version": "88.0",
"name": "XDM Browser Monitor",
"description": "XDM integration module for Firefox and Chromium based browsers",
"version": "2.0",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
},
"permissions": [
"tabs",
"cookies",
"contextMenus",
"activeTab",
"declarativeNetRequest"
],
"host_permissions": [
"http://*/*",
"https://*/*"
],
"commands": {
"toggle-monitoring": {
"suggested_key": {
"default": "Ctrl+Shift+E",
"mac": "Command+Shift+E"
},
"description": "Toggle monitoring"
}
}
}
new errrors : -1 : 'webRequestBlocking' requires manifest version of 2 or lower. : ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
{ "update_url": "https://clients2.google.com/service/update2/crx", "manifest_version": 3, "minimum_chrome_version": "88.0", "name": "XDM Browser Monitor", "description": "XDM integration module for Firefox and Chromium based browsers", "version": "2.0", "icons": { "48": "icon.png" }, "background": { "service_worker": "background.js" }, "action": { "default_icon": "icon.png" }, "permissions": [ "tabs", "cookies", "contextMenus", "activeTab", "webRequest", "webRequestBlocking" ], "host_permissions": [ "http:///", "https:///" ], "commands": { "toggle-monitoring": { "suggested_key": { "default": "Ctrl+Shift+E", "mac": "Command+Shift+E" }, "description": "Toggle monitoring" } } }