1

I have this in my Chrome extension manifest.json:

...

"content_scripts": [
    {
        "matches": ["http://*.youtube.com/playlist*", "https://*.youtube.com/playlist*"],
        "css": [],
        "js": ["jquery-2.1.3.min.js", "myscript.js"]
    }
]

And this is myscript.js:

 console.log('Running extension code!');

After installing the extension, I've run two experiments:

  • Experiment 1:
    I went directly to https://www.youtube.com/playlist?list=foo (by pasting the URL in the address bar and pressing <ENTER>). The console shows "Running extension code!", as expected.

  • Experiment 2:
    I went to https://www.youtube.com and then I manually navigated to a playlist (by clicking links), so the URL changed to https://www.youtube.com/playlist?list=foo. The console doesn't show the message, so the extension wasn't loaded.

I guess experiment 2 fails because YouTube is a Single Page Application (SPA). In SPAs, URLs change through code events.

Questions: What is the correct way of using content_scripts in here? Shouldn't be Chrome responsible of matching the URL and not me? (ie: is it a bug?)

sports
  • 7,851
  • 14
  • 72
  • 129
  • Specifically for YouTube: https://stackoverflow.com/questions/18397962/chrome-extension-is-not-loading-on-browser-navigation-at-youtube/18398921#18398921 – Rob W Mar 30 '15 at 20:31
  • Great!, exactly what I was looking for (and exactly what I wasn't able to find) – sports Mar 30 '15 at 20:34

0 Answers0