Content script won't run till I refresh page on youtube

4,505 views
Skip to first unread message

crosstheline db

unread,
Apr 19, 2015, 11:18:25 PM4/19/15
to chromium-...@chromium.org
Hi,

I have a Chrome extension which injects a content script into specific websites. One of them is Youtube. I have my manifest set as below:

content_scripts" : [
    {
      "matches" : [
      ],
      "js" : ["contentscript.js", "popup.js"],
      "run_at" : "document_idle",
      "all_frames" : false

When I open a new video link in youtube, it works just fine. But, from the video page, if I navigate to a new video link through say, related videos, a new video page with a new URL shows but my content script doesn't get injected. I think, this is caused by Youtube maintaining its top navbar and dynamically updating the rest of the page. How do I overcome this in my manifest/content script? I want my content script injected everytime user navigates to a new URL. 

P.S:- If I refresh the youtube page after moving to the new page, things work fine as expected.

Nuha Khaled

unread,
Jun 15, 2016, 3:34:43 AM6/15/16
to Chromium-Extensions-Announce
I got same issue. Did you find a solution for?

Yajie Xue

unread,
Jun 15, 2016, 3:45:07 AM6/15/16
to Nuha Khaled, Chromium-Extensions-Announce

Yes, youtube doesn’t reload the page when you go from one video to another, for this case, you could listen to [chrome.webNavigation.onHistoryStateUpdated]( https://developer.chrome.com/extensions/webNavigation#event-onHistoryStateUpdated), it fired when history was updated to a new URL. See this answer for more details http://stackoverflow.com/questions/36808309/chrome-extension-page-update-twice-then-removed-on-youtube/36818991#36818991

 

Thanks,

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/fd90076f-e341-42ee-9d90-43b862e03a3d%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Gaurav Chandiramani

unread,
Oct 3, 2016, 1:14:51 PM10/3/16
to Chromium-Extensions-Announce
I was stuck with something similar.
Here's what You can use a background script to check for a URL change. I used chrome.tabs.onUpdated.addListener for that. You can then send a message to the content script on a URL change.
You content script can then run when it receives the message from the background script. chrome.extension.onMessage.addListener should do that for you.

Hope this helps. 
Reply all
Reply to author
Forward
0 new messages