-2

I am having some problems creating Chrome extensions. The code affects all pages that are open in Chrome, how can I solve it?

My manifest.json:

{
    "manifest_version": 2,
    "name": "Merch Tools 41studio",
    "description": "report app",
    "version": "1.0",
    "background": {
        "scripts": ["assets/js/jquery.min.js", "assets/js/background.js"]
    },
    "browser_action": {
        "default_icon": "assets/image/icon.png",
        "default_popup": "popup.html"
    },
    "permissions": ["tabs"],
    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*"],
        "js": ["assets/js/jquery.min.js", "assets/js/highcharts.js"]
    }]
}
Makyen
  • 31,849
  • 12
  • 86
  • 121
Miftah Farid
  • 167
  • 1
  • 3
  • 12
  • 2
    don't target "all webs" – Jaromanda X Aug 15 '17 at 06:10
  • Can you tell me, how to make it? – Miftah Farid Aug 15 '17 at 06:15
  • 2
    can you show me what you've done? specifically the manifest – Jaromanda X Aug 15 '17 at 06:20
  • `{ "manifest_version": 2, "name": "Merch Tools 41studio", "description": "report app", "version": "1.0", "background": { "scripts": ["assets/js/jquery.min.js","assets/js/background.js"] }, "browser_action": { "default_icon": "assets/image/icon.png", "default_popup": "popup.html" }, "permissions": [ "tabs" ], "content_scripts": [ { "matches": ["http://*/*","https://*/*"], "js": [ "assets/js/jquery.min.js", "assets/js/highcharts.js" ] } ] } ` – Miftah Farid Aug 15 '17 at 06:27
  • 3
    `"matches": ["http://*/*","https://*/*"]` - well, you specifically match everything here – Jaromanda X Aug 15 '17 at 06:32
  • I suggest you read the [Chrome extension overview](https://developer.chrome.com/extensions/overview) (perhaps along with the pages linked from the overview). The [architecture section](https://developer.chrome.com/extensions/overview#arch) has overall architecture information which should help your understanding of how things are generally organized/done. You will probably also want to read [Content Scripts](https://developer.chrome.com/extensions/content_scripts). – Makyen Aug 16 '17 at 02:27

1 Answers1

1

You need to limit the list of domains your content scripts run on by changing the matches property in content_scripts. Having a "http://*/*","https://*/*" means the content script runs on all http and https websites. Rather you could specify a list of websites that you want the extension to run on.

{
  "manifest_version": 2,
  "name": "Merch Tools 41studio",
  "description": "report app",
  "version": "1.0",
  "background": {
    "scripts": ["assets/js/jquery.min.js", "assets/js/background.js"]
  },
  "browser_action": {
    "default_icon": "assets/image/icon.png",
    "default_popup": "popup.html"
  },
  "permissions": ["tabs"],
  "content_scripts": [{
    "matches": ["http:/yoursite.com/*"], // Change this to the sites you want your extension to run on
    "js": ["assets/js/jquery.min.js", "assets/js/highcharts.js"]
  }]
}
Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55