Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
chrome extension works on refresh/on land but not on 'internal navigation'

So simply when I land a page on youtube which starts with w* (meaning that a specific video with its ID) I'm firing alert(url) and it works however it only works when I land that page from the URL and/or on refresh. What I'm trying to achieve is to fire that alert when navigating to that page (watch?=...) FROM another youtube page meaning that I'm navigating internally.

as an example: www.youtube.com -> this is the landing page of youtube I click on a video and I navigate to: www.youtube.com/watch?=aiFUQ9981Qk

this DOES NOT trigger my alert HOWEVER when I refresh, it does trigger. how do i trigger even when i navigate 'FROM' 'WITHIN' youtube ? Any input would be appreciated. manifest and Content.js attached below...

manifest.json

{
    "manifest_version": 2,
    "name": "youtest",
    "version": "1.0.0",
    "content_scripts": [
        {
            "matches": ["https://*.youtube.com/watch?*"],
            "js": ["Content.js"]
        }
    ]
}

Content.js

console.log(window.location.href);
alert(window.location.href);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

function runScript() {
    if (window.location.href.indexOf('watch?') > -1) {
        alert('this is a video');
        let videoID = window.location.href.slice(
            window.location.href.lastIndexOf('/')
        );
        alert(videoID);
    } else {
        alert('not a video');
    }
}

document.addEventListener('yt-navigate-start', runScript);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!