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

[Question] Regarding CDP Session. #2484

Closed
shirshak55 opened this issue Jun 5, 2020 · 7 comments
Closed

[Question] Regarding CDP Session. #2484

shirshak55 opened this issue Jun 5, 2020 · 7 comments

Comments

@shirshak55
Copy link

shirshak55 commented Jun 5, 2020

I am converting all my puppeteer code which used to look like this.

https://github.com/shirshak55/scrapper-tools/blob/master/src/fastPage/index.ts#L113

const session = await page.target().createCDPSession()
  await session.send("Page.enable")
  await session.send("Page.setWebLifecycleState", {
    state: "active",
  })

So we went to docs and saw this

const client = await page.context().newCDPSession(page);

But now i am seeing error on typescript like this

Property newCDPSession doesn't exists on type BrowserContext

@pavelfeldman
Copy link
Member

pavelfeldman commented Jun 5, 2020

^^ @JoelEinbinder a ts types bug?

@JoelEinbinder
Copy link
Contributor

page.context() needs to be casted to ChromiumBrowserContext in order to use CDPSession

@shirshak55
Copy link
Author

shirshak55 commented Jun 6, 2020

@JoelEinbinder yep thanks I wrote

const session = await (page.context() as ChromiumBrowserContext).newCDPSession(page)

and it works but can you let me know why it requires page argument when it is already given page.context() ? I am asking because puppeteer doesn't use to require page argument? I think new syntax is not that ergonomic tbh.

Thanks :)

@Niek
Copy link

Niek commented Jul 1, 2020

The page parameter is strange indeed, as is the requirement to cast to ChromiumBrowserContext. Since all 3 supported browsers use CDP, it's unclear to me why the newCDPSession() method is not available in e.g FFBrowserContext.

Edit: I stand corrected, this is not true. See #2484 (comment)

@shirshak55
Copy link
Author

shirshak55 commented Jul 1, 2020

@Niek Yea casting and additional page argument is not ergonomic . And the api to launch persistent and non persistent is so different i was so shocked :(

See this https://github.com/shirshak55/scrapper-tools/blob/5c216cd7b0894f16f2d07128b20812523e3afb1a/src/fastPage/index.ts#L137

@aslushnikov
Copy link
Collaborator

Since all 3 supported browsers use CDP

@Niek this is not actually the case.

  • In Chromium we rely on CDP
  • In WebKit we rely on "Web Inspector Remote Debugging Protocol"
  • In Firefox we rely on "Juggler" protocol

@Niek
Copy link

Niek commented Jul 2, 2020

  • Juggler

Since all 3 supported browsers use CDP

@Niek this is not actually the case.

  • In Chromium we rely on CDP
  • In WebKit we rely on "Web Inspector Remote Debugging Protocol"
  • In Firefox we rely on "Juggler" protocol

Apologies @aslushnikov, I assumed Playwright (just like Puppeteer) used CDP for FF now that it's built-in (and enabled in at least the nightly builds). But reading #1765 (comment) that's not the case until the CDP support in FF is more mature.

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