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

[Feature] Expose page.target() #783

Closed
umanghome opened this issue Jan 31, 2020 · 3 comments · Fixed by #790
Closed

[Feature] Expose page.target() #783

umanghome opened this issue Jan 31, 2020 · 3 comments · Fixed by #790

Comments

@umanghome
Copy link

We're opening a popup and need to get its parent. Puppeteer give a page.target API that lets us do that.

Target is present as a Symbol on the Page, but there's API that exposes it. It would be great if there was a way to get a reference to it. Currently using this hack:

/**
 * Playwright doesn't expose an API to get the target.
 * This is a hack to get it.
 * @param {Page} page
 *
 * @returns {Target}
 */
function getTarget(page) {
  const symbol = Object.getOwnPropertySymbols(page).find(
    symbol => String(symbol) === 'Symbol(target)'
  );

  if (!symbol) {
    return;
  }

  return page[symbol];
}
@umanghome umanghome changed the title [Feature] Expose page.target [Feature] Expose page.target() Jan 31, 2020
@yury-s
Copy link
Member

yury-s commented Jan 31, 2020

There is no such API in Playwright today. You learn about new popups by listening to the popup event on the opener so you should already now what it is for each new popup page. Can you provide some details on why it is not sufficient in your scenario?

@umanghome
Copy link
Author

The popup event doesn't seem to work for my case. targetcreated seems to work, though. Moving it to a #873.

@umanghome
Copy link
Author

This seems to be incorrectly closed too. I'm trying to get the CRTarget associated with a Page. page.opener() just gives me the opener's CRTarget.

sand4rt pushed a commit to sand4rt/playwright that referenced this issue Dec 21, 2022
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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

Successfully merging a pull request may close this issue.

2 participants