Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

google chrome - "exclude_matches" in manifest.json does nothing?

I'm having a problem controlling what pages my content scripts are injected into. The chrome extension developer guide specifies that I can use an "exclude_matches" directive in my manifest.json to exclude certain pages from injection.

However, this doesn't seem to have any effect. My content script still executes on pages that I have specified as ignored.

I have put the steps to reproduce in a Gist. The code is also available on Github.

Any ideas what I'm doing wrong?

manifest.json

{
  "name": "Testing Extension",
  "version": "1.0",
  "description": "Test the chrome extensions exclude_matches.",
  "content_scripts": [{
    "matches": ["http://*/*", "https://*/*"],
    "exclude_matches": ["http://news.ycombinator.com/"],
    "js": ["content.js"]
  }]
}

content.js

console.log("hello from the content script");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is Bug #100106. exclude_matches do not function properly.

To solve the problem, use exclude_globs instead of exclude_matches.

Also, your exclude_matches rule does only match http://news.ycombinator.com/.
Suffice the pattern with an asterisk to match the whole site: http://news.ycombinator.com/*.

See also: Match patterns.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...