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

138
Visualizações
Open browser window and search for tags

I build something that you can execute in a browser console that searches the site for links and returns an array of links. After that I want to go trough each link, open the linkpage and search for all tags and get the source.

The pages have the same domain and only the part in the end is different. But when I try to execute my code it opens the first window. Returns undefined and closes the window. After that I get this error: VM79:32 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getVideoSources') at <anonymous>:32:51

The part where I get the links works perfectly and it returns a list of links. Now the part that causes me problems is where I try to open each link.

async function grabLinks(links) {
const videoList = [];
for (const link of links) {
    console.log("New link!")
    // Go trough each link and get the video sources
    const sources = await getVideoSources(link);
    videoList.push(...sources);
}
console.log(videoList);
showLinks(videoList)
}

function getVideoSources(link) {
return new Promise((resolve, reject) => {
    console.log("Opening Window");
        const openedWindow = window.open(link, "_blank");
        openedWindow.focus();
        openedWindow.addEventListener("DOMContentLoaded", () => {
            try {
                const videoElements = openedWindow.document.querySelectorAll("div video");
                var source = videoElements[0].getVideoSources;
                console.log(source)
                resolve(source);
            } catch (e) {
                reject(e);
            } finally {
                openedWindow.close();
                console.log("Closing Window");
            }
        });
});
}

How would I go about and fix this problem. Should I add a timeout of like 5s and let the page fully load or what exactly goes wrong here.

about 4 years ago · Juan Pablo Isaza
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