KingPolygon
KingPolygon

Reputation: 4755

Chrome Extensions: Running Different .js Files Depending on What Site You're On?

I'm new to chrome extensions but I have a question concerning content scripts.

I want to execute a specific js file if the user accesses a specific domain, and another different js file if they access a different one.

My question is, how can I do this inside the manifest.json file?

This is what I have so far:

    "content_scripts": 
         [{"matches": ["http://store.example.com/*"], "js": ["store.js"]}], 
         [{"matches": ["https://purchase.example.com/*"], "js": ["purchase.js"]}]

    "permissions":["tabs", "http://store.example.com/*"]

But I keep getting an error. Thank you!!

Upvotes: 1

Views: 133

Answers (1)

Jude Osborn
Jude Osborn

Reputation: 1798

The format of your content_scripts declaration is incorrect. Try this:

"content_scripts": [
    {"matches": ["http://store.example.com/*"], "js": ["store.js"]},
    {"matches": ["https://purchase.example.com/*"], "js": ["purchase.js"]}
],

Upvotes: 2

Related Questions