0

I have a content script and I only want it to match https://fantasy.premierleague.com/a/team/my so I added the following to my manifest.json

"content_scripts": [
  {
    "matches": ["*://fantasy.premierleague.com/a/team/my"],
    "js": ["myTeam.bundle.js"],
    "run_at": "document_idle"
  }
],

However, it is still matching pages like https://fantasy.premierleague.com/a/home and https://fantasy.premierleague.com/a/team/123456/event/12. Why is this happening?

Even after adding the following

"exclude_matches": ["https://fantasy.premierleague.com/a/home"],

it still executes on that page!

Amos
  • 1,154
  • 1
  • 16
  • 35
  • 1
    I guess that's an AJAX-driven site. It means the subsequent navigation doesn't load the page from the server entirely, but instead it fetches the data, changes portions of the page, alters the displayed URL. Your content script was loaded on a properly matched URL before navigation and it stays active afterwards. If my guess is correct you can use chrome.tabs.onUpdated in your background script and send a message to the content script to tell it to deactivate when the URL doesn't match. – wOxxOm Nov 11 '18 at 19:30
  • @wOxxOm it could very well be that. Could you explain how to do this in further detail? – Amos Nov 11 '18 at 19:40
  • See https://stackoverflow.com/q/34077641/934239 for some more information. – Xan Nov 15 '18 at 15:13
  • Or this: https://stackoverflow.com/questions/4646360/monitoring-history-pushstate-from-a-chrome-extension – Xan Nov 15 '18 at 15:14

0 Answers0