0

I am trying to use History.pushState() to change the URL of the Youtube results page (typed in an input into the search box in youtube home page and clicking search). It is not showing, and I cannot figure out why.

Here is what I have so far (I'm sending message to another script, but thats not very important to this problem):

if (window.location.href.includes('/results')) {
   history.pushState({id: 'results'}, '', 'searchedVideos');       
   chrome.runtime.sendMessage({message: 'results'});
}

An answer to this will be extremely helpful. Thank you!

Edit: This is my manifest.json:

{
  "matches": ["*://www.youtube.com/results*"],
  "css": ["results.css"],
  "js": ["content.js"],
  "run_at": "document_idle"

},

{
  "matches": ["https://www.youtube.com/"],
  "css": ["home.css"],
  "js": ["content.js"],
  "run_at": "document_idle"
},

{
  "css": ["videoRec.css"],
  "matches": ["https://www.youtube.com/watch*"],
  "run_at": "document_idle"
}
colinified101
  • 39
  • 1
  • 3
  • Extensions have many moving parts so the question is unanswerable currently. Show your manifest.json and indicate where this code runs. – wOxxOm Dec 20 '20 at 15:38
  • I've edited my post. Thanks. – colinified101 Dec 21 '20 at 01:53
  • Youtube is a Single Page Application site so it doesn't use normal navigation. Your `matches` should match the entire site: `"*://www.youtube.com/*"` - don't forget the `*` at the end. See also [How to detect page navigation on YouTube and modify its appearance seamlessly?](https://stackoverflow.com/a/34100952) – wOxxOm Dec 21 '20 at 07:32

0 Answers0