Regarding issue in chrome extension development

323 views
Skip to first unread message

Abhishek Sinha

unread,
Nov 12, 2023, 1:22:33 PM11/12/23
to Chromium Extensions
Hello, I am trying to develop a extension to redirects the page to google.com if a 404 status code is reached without using netRequest API or webBlockingAPI
Here is my manifest file
{
  "name": "404 Redirect",
  "version": "1.0",
  "description": "Redirects to google.com if a 404 status code is reached",
  "manifest_version": 3,
  "permissions": ["activeTab"],
  "background": {
    "service_worker": "background.js"
  }
}
and here is my background.js file
chrome.webNavigation.onCompleted.addListener(function (details) {
  if (details.statusCode === 404) {
    chrome.tabs.update({ url: "https://www.google.com" });
  }
});

 I am getting the following errors:
Service worker registration failed. Status code: 15
Uncaught TypeError: Cannot read properties of undefined (reading 'onCompleted')

What am I doing wrong?

Patrick Kettner

unread,
Nov 12, 2023, 1:38:53 PM11/12/23
to Abhishek Sinha, Chromium Extensions
The error mentions that incomplete does not exist on undefined. That means that whatever you are trying to use onCompleted on does not exist. In your code, that would be chrome.webNavigation. Checking the docs for that API, 
https://developer.chrome.com/docs/extensions/reference/webNavigation/, it shows that the permission “webNavigation” is needed, which is missing in your manifest file. 

Add it, and you’ll be good to go. 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/cdb2b64c-c8e2-4716-b143-3ca74dad2da9n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages