foxr icon indicating copy to clipboard operation
foxr copied to clipboard

browser.pages() returns same URL and title for all pages

Open AfzalivE opened this issue 4 years ago • 6 comments

const browser = await foxr.connect()
const pages = await browser.pages()

the pages const returns the following, instead of details of each page

[{"_events":{},"_eventsCount":0,"_browser":{"_events":{"disconnected"
:[null,null,null,null,null]},"_eventsCount":1},"_id":"50"},{"_events":{},"_eventsCount":0,"_browser
":{"_events":{"disconnected":[null,null,null,null,null]},"_eventsCount":1},"_id":"52"},{"_events":{
},"_eventsCount":0,"_browser":{"_events":{"disconnected":[null,null,null,null,null]},"_eventsCount"
:1},"_id":"54"},{"_events":{},"_eventsCount":0,"_browser":{"_events":{"disconnected":[null,null,nul
l,null,null]},"_eventsCount":1},"_id":"56"}]

Is this intentional or is something happening that I'm not aware of?

Thanks

AfzalivE avatar Dec 19 '19 23:12 AfzalivE

that's how pages looks like when you print it to console, actually it's an array of pages that should work as intended, just like in Puppeteer.

deepsweet avatar Dec 20 '19 08:12 deepsweet

hmm, but when I did page.title(), that was blank too for all of them :/

edit: Ah nvm, that's also an async function. Thanks for this library! Very useful!

AfzalivE avatar Dec 20 '19 08:12 AfzalivE

@deepsweet Okay slightly different issue but:

    const pages = await browser.pages()
    log.info(`Found ${pages.length} pages`)

    log.info((await pages[0].title()))
    log.info((await pages[1].title()))

when I do this (where log.info is just a logging line), it prints the same title for all pages, and same url. Even though they're different tabs with different URLs

AfzalivE avatar Dec 20 '19 08:12 AfzalivE

sounds like an interesting bug, I'll take a look early next week. thanks!

deepsweet avatar Dec 20 '19 19:12 deepsweet

Yeah so the reason for this is that it doesn't look like Selenium has any capability of getting content or title for all window handles. Only able to get that from the active one.

So it's basically

for (page of pages) {
  await page.bringToFront()
  await page.title() // and now the title will be correct
}

Would be nice if foxr can do this by itself though

AfzalivE avatar Dec 21 '19 06:12 AfzalivE

I can confirm @AfzalivE's described behavior

alexbartisro avatar May 03 '20 16:05 alexbartisro