Manifest.JSON Multiple content_scripts

3,730 views
Skip to first unread message

Matthew Kaufer

unread,
Nov 9, 2013, 2:07:46 PM11/9/13
to chromium-...@chromium.org
Hi,

The following code is in my manifest.json. However, Chrome states that there is an invalid value at content_scripts[1].exclude_matches[0] with an invalid scheme. The code is below.

  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "js": ["jquery-1.10.2.min.js"],
      "run_at": "document_end"
    },
    {
      "matches": ["*://*/*"],
      "exclude_matches": ["chrome://newtab"],
      "js": ["script.js"],
      "run_at": "document_end"
    }
  ]

I don't want the script.js code to run on the new tab page. Is there a way to fix the JSON? jsonlint says it looks fine.

Paulie

unread,
Nov 9, 2013, 2:36:59 PM11/9/13
to chromium-...@chromium.org
Where did you get that exclude_matches from? I don't think there is a way to exclude matches.

Can't you just do a check to see what the window.location.indexof or window.location.protocol is and then not run any code if it matches that variable?

E.g. in your script file have an initial function with an if statement or something?

function init(){

if(window.location.protocol != "chrome:"){
//RUN YOUR SCRIPT.JS CODE
}

}
 init();

Adrian Aichner

unread,
Nov 9, 2013, 2:45:00 PM11/9/13
to Paulie, Chromium-extensions
On Sat, Nov 9, 2013 at 8:36 PM, Paulie <paulie...@gmail.com> wrote:
Where did you get that exclude_matches from? I don't think there is a way to exclude matches.

--
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 post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/c1fedfff-7a92-43ab-95c5-9c1ea23adda6%40chromium.org.

Adrian Aichner

unread,
Nov 9, 2013, 2:47:31 PM11/9/13
to Matthew Kaufer, Chromium-extensions
On Sat, Nov 9, 2013 at 8:07 PM, Matthew Kaufer <mjka...@gmail.com> wrote:
Hi,

The following code is in my manifest.json. However, Chrome states that there is an invalid value at content_scripts[1].exclude_matches[0] with an invalid scheme. The code is below.

But you can't have more than one content_scripts property.


jsonlint wouldn't know that, of course.

Also read
carefully.

chrome is not a supported scheme.
 

  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "js": ["jquery-1.10.2.min.js"],
      "run_at": "document_end"
    },
    {
      "matches": ["*://*/*"],
      "exclude_matches": ["chrome://newtab"],
      "js": ["script.js"],
      "run_at": "document_end"
    }
  ]

I don't want the script.js code to run on the new tab page. Is there a way to fix the JSON? jsonlint says it looks fine.

--
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 post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

PhistucK

unread,
Nov 9, 2013, 3:43:26 PM11/9/13
to Adrian Aichner, Matthew Kaufer, Chromium-extensions
content_scripts is an array, so while you cannot have multiple arrays, you can have multiple content scripts within the array.
chrome is indeed not a supported scheme.

Generally, the content script is not supposed to even run on the New Tab page, since it is an internal page. It might be that you are part of the (very widespread) experiment in which the new tab page is actually the Google Search home page.
So in order to exclude it, perhaps excluding Google search using the exclude_matches key would work, or perhaps you should just check for it within your content script, like Paulie suggested, or maybe look for some properties of the Embedded Search API (which the Google Search based New Tab page uses).

Also, please, do not start multiple threads for the same topic.


PhistucK


Adrian Aichner

unread,
Nov 9, 2013, 3:58:48 PM11/9/13
to PhistucK, Matthew Kaufer, Chromium-extensions
On Sat, Nov 9, 2013 at 9:43 PM, PhistucK <phis...@gmail.com> wrote:
content_scripts is an array, so while you cannot have multiple arrays, you can have multiple content scripts within the array.
chrome is indeed not a supported scheme.

Ah, right, I have that array in my manifest.

So that's a bug in
then!

It does not show the square brackets.

is correct though.

Adrian Aichner

unread,
Nov 9, 2013, 4:05:57 PM11/9/13
to PhistucK, Matthew Kaufer, Chromium-extensions
I haven't found this reported, so here goes:


http://developer.chrome.com/extensions/manifest.html lacks [] in "content_scripts": {...},

Adrian Aichner

unread,
Nov 12, 2013, 9:20:48 AM11/12/13
to PhistucK, Matthew Kaufer, Chromium-extensions
http://developer.chrome.com/extensions/manifest.html#overview
now correcly shows
"content_scripts": [{...}],
instead of the previously incorrect
"content_scripts": {...},

Looking back in the thread reveals I misinterpreted that

invalid value at content_scripts[1].exclude_matches[0] with an invalid scheme

Matthew's use of content_scripts was correct, it was just the value of exclude_matches[0] which was not supported.

But the doc fix was in order anyway.

Reply all
Reply to author
Forward
0 new messages