Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension Manifest 'Matches'

I'm trying my hands at a simple Chrome Extension, but am running into a problem with providing a value for the matches array in my content_scripts.

{   "name": "My Extension",   "version": "1.0",   "description": "My Extension Experiment",   "browser_action": {     "default_icon": "icon.png",     "default_title": "Ext",     "default_popup": "popup.html"   },   "content_scripts": {     "matches": ["http://*"],     "js": ["scripts.js"]   } } 

When I try to load this extension into Chrome, I get the following message:

Could not load extension from 'C:\Users\foo\Desktop\Extensions\bar'.
Invalid value for 'content_scripts'.

I cannot see what is "invalid" about my value though. What I'm trying to do is match every URL, so my extension can manipulate the DOM (via javascript within scripts.js) of any page it is ran on. Am I missing something, going about this all wrong, or what?

update

After posting this question, I did notice that the Google example was slightly different than mine, so I modified my code a bit to reflect their syntax:

"content_scripts": [{   "matches": ["http://*"],   "js": ["scripts.js"] }] 

That being said, I still get the following error when trying to load my extension:

Could not load extension from 'C:\Users\foo\Desktop\Extensions\bar'.
Invalid value for 'content_scripts[0].matches[0]'.

like image 756
Aristotle Avatar asked May 04 '10 22:05

Aristotle


People also ask

What is a manifest file Chrome extension?

The manifest establishes the name, version, and description of our chrome extension as well as the background script, popup and options pages. It also establishes where we can inject foreground scripts (more on that later…).

How do I see chrome manifest extensions?

Open chrome://version/ and find the "Profile Path:` field. Open that folder up. All your extensions are here, with typically readable source.

Is manifest V2 still supported?

Manifest V3 is an initiative of the Chromium project. Manifest V2 support ends in June of 2023 for all Chromium-based browsers. An overview of the changes involved, as described in Overview of Manifest V3 - Chrome Developers: Service workers will replace background pages.

Is manifest V2 deprecated?

"Manifest version 2 is deprecated, and support will be removed in 2023."


2 Answers

You need to surround the value of the content_scripts field in square brackets:

"content_scripts": [ {   "matches": ["http://*"],   "js": ["scripts.js"] } ] 

(see the Chrome Docs for more info)

Incidentally, using http://*/* would be a better match for all urls (see the docs), adding https://*/* if you also need to match those as well.

Edit:

Following your edit, the error you are getting is because of the match pattern being incorrect.

like image 79
adrianbanks Avatar answered Oct 01 '22 07:10

adrianbanks


If you want to match every URL, then Google has a special pattern just for this purpose: <all_urls>

Sample usage:

"matches": ["<all_urls>"], 

See this page for more info: https://developer.chrome.com/extensions/match_patterns

like image 41
thdoan Avatar answered Oct 01 '22 08:10

thdoan