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

137
Views
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
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!