Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make page bring to front #2603

Closed
phileba opened this issue Jun 17, 2020 · 7 comments
Closed

How to make page bring to front #2603

phileba opened this issue Jun 17, 2020 · 7 comments

Comments

@phileba
Copy link

phileba commented Jun 17, 2020

Do we have a method to make to browser page on top likes page.bringToFront() or something like that?

@yury-s
Copy link
Member

yury-s commented Jun 17, 2020

Each page created in Playwright behaves as if it was focused active page so bringToFront would be noop. Can you share more details about the use case where you need such method?

@phileba
Copy link
Author

phileba commented Jun 18, 2020

@yury-s I have the context it the browser opening more than one page, then I can get all pages by this method page.context().pages(), so if I want to bring to a front specific page of that list, how can I do?

await page.goto('page_1.html')
page.context().on('page', async newPage => {
	console.log(await newPage.title()) // log title of page_2.html
})
await page.click(By.tagName('a')) // open page_2.html in new tab
await page.waitForTimeout(2000)
for (const page of page.context().pages()) {
	console.log(await page.title()) // page_1.html title and page_2.html title
        //how can make page_1.html bring to front
}

@phileba
Copy link
Author

phileba commented Jun 22, 2020

@yury-s do you have any updates?

@yury-s
Copy link
Member

yury-s commented Jun 22, 2020

In your snippet even if you had page.bringToFront() calling it would make no difference to the pages' because all of them are already active and focused. Note that it's not obvious in the headful mode because OS usually doesn't allow multiple focused windows but otherwise from what could be detected in the page's javascript the page is already 'top' page.

Does your page somehow depend on 'document.visibilityState' or how would it detect that it's brought to top? For the visibilityState there is an easy way to mock it in the client code which is described in #1290, would that work for you?

@dgozman
Copy link
Contributor

dgozman commented Aug 14, 2020

Playwright 1.3 now has page.bringToFront() method.

@dgozman dgozman closed this as completed Aug 14, 2020
@tuanvhit
Copy link

Still fails on firefox

@tovab
Copy link

tovab commented Jun 9, 2022

My test was also failing specifically on Firefox because the tab I was working with was not the active tab.
page.bringToFront() did not work for me.
I solved the issue by closing the other tab using
await page.context().pages().at(_index_)?.close();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants