Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Chrome Extension get the details of the music being played on YouTube Music

I want to create a Chrome Extension and I need to get the details of the music that is being played on YouTube Music. Is there any way to do that (maybe using JS to get the name of the music or whatever). Any kind of help is appreciated

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can run content scripts on the Youtube Music website & app and parse the HTML to get the info you need. Here's a quick script with lazy code. You should obviously do the detection and error-handling better.

Manifest:

{
    "manifest_version": 3,
    "name": "Youtube Music Info",
    "version": "1.0",
    "description": "Gets information from YT Music.",
    "content_scripts": [
        {
            "matches": [ "https://music.youtube.com/*" ],
            "js": [ "content.js" ],
            "all_frames": false,
            "run_at": "document_start"
        }
    ]
}

Content Script:

let ytmusicPlayerBar

let waitForPlayerBarInterval = setInterval(() => {

    if (document.querySelector("ytmusic-player-bar")) {
        ytmusicPlayerBar = document.querySelector("ytmusic-player-bar")
        clearInterval(waitForPlayerBarInterval)
        getInfo()
    }

}, 1000)

function getInfo() {

    let getInfoInterval = setInterval(() => {

        if (ytmusicPlayerBar.querySelector(".title").innerText) {

            let info = {
                song: ytmusicPlayerBar.querySelector(".title").innerText,
                artist: ytmusicPlayerBar.querySelectorAll("a")[0].innerText,
                albumName: ytmusicPlayerBar.querySelectorAll("a")[1].innerText,
                albumCover: ytmusicPlayerBar.querySelector(".image").src,
                time: ytmusicPlayerBar.querySelector(".time-info").innerText
            }
        
            console.log(info)

        } else {
            console.log("Nothing is playing.")
        }

    }, 1000)

}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda