Google Chrome extension match pattern for new tab

Hi,

I am writing a simple extension for Google Chrome browser which will trigger a js file when an empty new tab page is opened. My manifest.json file is as follows, which works for all URLs, but not for the new tab since it doesn’t have a URL (at least visible).

{
  "manifest_version": 2,
  "name": "Test Extension",
  "description": "Just testing.",
  "version": "0.1",
  
  "content_scripts": [
  {
    "matches": [
      "<all_urls>"
    ],
    "js": ["script.js"]
  }
  ]
}

I know I need to change the matches section so the script.js will be triggered on the new tab but I couldn’t figure how to make it work for new tab. Any ideas welcome.

Do you want to create your own new tab page?

I want my extension to detect when the default (empty) new tab page is opened. If possible.

Hello Nayen, As you know that the Content Script matching is based on a set of URLs defined by Match Patterns and Match Pattern is a URL that begins with a permitted scheme. Due to security reason, chrome only provides following permitted schemes,

  1. HTTP
  2. HTTPS
  3. FILE
  4. FTP
    Lets come to problem,
    The match pattern of New Tab is chrome://newtab but google chrome doesn’t permit to use chrome(of chrome://newtab) scheme in Content Scripts and Host Permissions and if use this it will generate error.
    So there is only one way to trigger an action is create new tab.
    i hope you will get my point.

Thank you, this clarifies things for me. I guess I will go with “create my own new tab page” option.

Welcome :blush:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.