greygoody / xdm-browser-monitor-manifest-version-3

modification to compliance with manifest version 3 for chromium browsers
0 stars 0 forks source link

Edge browser errors after commit "f89387d9d54a6825ec16f8ab0c533b1c36e02b44" #1

Open greygoody opened 2 months ago

greygoody commented 2 months ago

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" } } }


-2 : Unchecked runtime.lastError: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest. Note that webRequestBlocking is only allowed for extensions that are installed using ExtensionInstallForcelist.
Context

Unknown

Stack Trace

:0 (anonymous function)

-3 : Unchecked runtime.lastError: Extensions using event pages or Service Workers must pass an id parameter to chrome.contextMenus.create
Context

Unknown

Stack Trace

:0 (anonymous function)

-4 : Uncaught (in promise) Error: Failed to set icon 'icon48.png': Failed to fetch
Context

extensions::setIcon

Stack Trace

extensions::setIcon:149 (anonymous function)

-5 : Uncaught (in promise) Error: Failed to set icon 'icon16.png': Failed to fetch

Context

extensions::setIcon

Stack Trace

extensions::setIcon:149 (anonymous function)
greygoody commented 2 months ago

Issue 1: 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.

Updated Manifest File:

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"
    }
  }
}

Updated 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...

Issue 2: webRequestBlocking permission issue.

This issue will be resolved by switching to declarativeNetRequest as shown above.

Issue 3: 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.

Issue 4 and 5: 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"
  }
}

Final Updated Manifest File:

{
  "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"
    }
  }
}