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 tohttps://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 tohttps://www.youtube.com
and then I manually navigated to a playlist (by clicking links), so the URL changed tohttps://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?)