0

I'm creating a google extension that redirects the user to a link whenever they open a new tab. I don't understand why the listeners aren't working though, the extension doesn't do anything when I open a new tab. Here is my manifest (manifest.json):

{
  "name": "Insert Name Here",
  "description": "Insert description here",
  "version": "1.0",
  "manifest_version": 3,
  "action": {
    "default_icon": "icon.png",
    "default_popup": "hello.html"
  },
  "background.service_worker": {
    "scripts": [ "popup.js" ],
    "persistent": false
  },
  "permissions": [
    "tabs"
  ]
}

Here is my javascript file (popup.js):
chrome.tabs.onCreated.addListener(function () {
    chrome.tabs.update({
        tabId: WINDOW_ID_CURRENT,
        url: "https://www.youtube.com/*"
    })
});

Nothing happens when I open the window and I would like it to redirect to a YouTube link whenever a new tab is opened.

  • Please see this. [Chrome Extension - storing the URL before the request is made, not working?](https://stackoverflow.com/questions/75859819/chrome-extension-storing-the-url-before-the-request-is-made-not-working/75863109#75863109) – Norio Yamamoto Mar 29 '23 at 01:48
  • There are several mistakes in your code: 1) using the same script in popup and background, 2) `background` declaration is [incorrect](/a/65451580). But first it's unclear what this code is supposed to do. Currently it wants to open and focus a new tab for youtube in addition to the empty start tab opened by the user that will be left hanging in background. If you want to replace the start tab, use [chrome_url_overrides](https://developer.chrome.com/extensions/override). – wOxxOm Mar 29 '23 at 10:08

0 Answers0