Definitelytyped: [@types/puppeteer] Missing definition for "page._client"

Created on 4 May 2018  路  5Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the puppeteer package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [ ] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @marvinhagemeister

    • Authors: @cdeutsch

    • Authors: @jwbay

The definition for "page._client" is missing or more accurate, the attribute "_client" is missing.
let page = await browser.newPage();
page._client.send(...) // <-

Most helpful comment

const client = await page.target().createCDPSession();
await client.send('Emulation.clearDeviceMetricsOverride')

All 5 comments

Although JavaScript doesn't have native support for private properties, the community more or less has settled on using the _-prefix to denote that this property/variable should not be used outside of the specific package. Since it is not part of the public API of puppeteer (it is not mentioned in their API-Documentation), it should not be exposed via our typings.

This would be really bad, because many options like setting the downloadfolder, downloadbehaviour and more can only be controlled by this attribute. All answers on questions related to those settings are pointing to that attribute and methode. So you HAVE to use it, regardless of the status of the documentation. Everybody who wants to use typescript with puppeteer and needs to change settings will encounter this problem. And i think most coders will maybe just switch back to plain js.
What about implementing it as "any" but noting within the type-definition that this is maybe experimental?

@mhombach I think a better solution to resolve the situation would be to poke the puppeteer developers to make this api public.

Besides, the workaround by casting to any works regardless of our types:

const page = await browser.newPage();

// simply cast to any
(page as any)._client.send();

EDIT: They already have an issue about this: https://github.com/GoogleChrome/puppeteer/issues/299

I believe this is now exposed (and typed) as CDPSession

const client = await page.target().createCDPSession();
await client.send('Emulation.clearDeviceMetricsOverride')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fasatrix picture fasatrix  路  3Comments

tyv picture tyv  路  3Comments

demisx picture demisx  路  3Comments

Zzzen picture Zzzen  路  3Comments

ArtemZag picture ArtemZag  路  3Comments