Search code examples
google-chrome-extensionpermissionsmanifestcontent-script

Chrome Extension: Difference between "permissions" and "matches" (match patterns)


I am trying to understand, what is the difference between:

  "permissions": [
    "*.google.com"
  ],

and

"content_scripts": [
    {
      "matches": ["*.google.com"]
    }
  ]

Solution

  • 1. Permissions for domains

    Web pages can not make Cross-Origin XMLHttpRequest (AJAX), but extensions can. Adding the domain in permissions will allow you to do ajax requests to the specified domain from your content scripts.

    2. Matches

    Content scripts work inside loaded pages. With matches you are able to specify inside which pages you want to inject your content scripts.

    Example: I want to fetch weather data from openweathermap.org, and present the data only on google.com pages.

    "permissions": [
      "http://api.openweathermap.org/*"
    ],
    "content_scripts": [
      {
        "matches": ["https://*.google.com/*"],
        "js": ["js/content.js"]
      }
    ]