Commit Graph

134 Commits

Author SHA1 Message Date
Jack Franklin
f1a6b8d66d
chore: vendor Mitt & update project structure (#6209)
* chore: vendor Mitt into src/common/third-party

As discussed in #6203 we need to vendor our common dependencies in so
that when we ship an ESM build all imports point to file paths and do
not rely on Node resolution (e.g. a browser does not understand `import
mitt from 'mitt'`).
2020-07-14 16:57:29 +01:00
Jack Franklin
31309b0e20
chore: use devtools-protocol package (#6172)
* chore: Use devtools-protocol package

Rather than maintain our own protocol we can instead use the devtools-protocol package and pin it to the version of Chromium that Puppeteer is shipping with.

The only changes are naming changes between the bespoke protocol that Puppeteer created and the devtools-protocol one.
2020-07-10 11:51:52 +01:00
Jack Franklin
f666be3f5f
chore: remove src/api.ts (#6191)
Now the async hooks helper is gone api.ts was only used by the coverage
tools and by doclint.

DocLint is nearing the end of its lifespan with the TSDoc work, so I
focused on how best to define a list of modules for the coverage
tooling. They define an object of classes, and the path to that module.
They need the full path because we also check if the module exports any
events that need to be emitted - the coverage tool asserts that the
emitting of those events is also tested.

It's not _great_ that DocLint relies on a constant defined in the
coverage utils, but it should only be this way for a short period of
time and no one is actively working on DocLint (bar the effort to remove
it) so I don't think this is worth worrying about.

This change also broke the DocLint tests; based on the fact that DocLint is on its way out it doesn't feel worth fixing the tests, so this commit also removes them.
2020-07-10 10:07:28 +01:00
Jack Franklin
24cb6a28ad
chore(docs): document Frame class (#6188)
* chore: document Frame class
2020-07-09 14:22:58 +01:00
Christian Bromann
e67a860eb0
feat: add Mouse#wheel (#6141) 2020-07-06 09:27:17 +02:00
Jack Franklin
f7857d27c4
chore(docs): document HTTPRequest with TSDoc (#6146)
* chore(docs): document HTTPRequest with TSDoc

* doclint

* example
2020-07-03 14:28:45 +01:00
Jack Franklin
29f7e161b1
chore(docs): reduce warnings when generating docs (#6138)
* chore(docs): reduce warnings when generating docs

This is a bunch of small miscellaneous fixes that reduce the amount of
warnings logged when generating our new docs. The long term goal is to
get this list down to 0 warnings, but I'll do it in multiple PRs.

* satisfy doclint
2020-07-02 12:15:39 +01:00
Jack Franklin
6474edb9ba
feat(types): add types for $eval (#6135)
This pulls in the types (based on the DefinitelyTyped repo) for
`page.$eval` (and the `$eval` method on other classes). The `$eval`
method is quite hard to type due to the way we wrap and unwrap
ElementHandles that are passed to / returned from the `pageFunction`
that users provide.

Longer term we can improve the types by providing type overloads as
DefinitelyTyped does but I've deferred that for now (see the `TODO` in
the code for more details).
2020-07-02 10:09:34 +01:00
Yang Guo
123c377512
docs(new): Add TSDoc to Coverage class (#6106) 2020-06-29 09:53:28 +01:00
Jack Franklin
1c0009d2c0
chore(agnostic): ship CJS and ESM builds (#6095)
* chore(agnostic): ship CJS and ESM builds

For our work to enable Puppeteer in other environments (e.g. a browser)
we need to ship an ESM build. This commit changes our config to ship to
`lib/cjs` and `lib/esm` accordingly. The majority of our code stays the
same, with one small fix for the CJS build to ensure that we ship a
version that lets you `require('puppeteer')` rather than have to
`require('puppeteer').default`. We do this with the `cjs-entry.js` which
is what the `main` field in our `package.json` points to.

We also swap to `read-pkg-up` to find the `package.json` file. This is
because the folder structure of `lib/` does not match `src/` now we ship
to `cjs` and `esm`, so you cannot rely on exact paths. This module works
up from the file to find the nearest `package.json` so it will always
find Puppeteer's `package.json`.

Note that we *do not* point any users to the ESM build. We happen to
ship those files so people who know about them can get at them but it's
not expected (nor will we actively support) that people will rely on
them. The CommonJS build is considered our main build.

We may make breaking changes to the structure of the ESM build which we
will do without requiring new major versions. For example the ESM build
currently ships all files that the CJS build does, but given we are
working on the ESM build being able to run in the browser this may
change over time.

Long term once the Node versions catch up we can ditch CJS and ship
exclusively ESM but we are not there yet.
2020-06-25 14:24:46 +01:00
Jack Franklin
37f6032003
feat(api): remove emulateMedia method (#6084)
It has been deprecated for a while. In the next breaking release let's remove it.

BREAKING CHANGE: swap to `emulateMediaType` instead.
2020-06-23 16:27:37 +01:00
Peter Marshall
ccae54644c
docs(new): migrate Browser docs to TSDoc (#6070) 2020-06-23 07:19:15 +02:00
Alex Rudenko
6657364364
docs(new): migrate ElementHandle to TSDoc (#6073)
* docs(new): migrate ElementHandle to TSDoc

Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
2020-06-22 17:21:57 +02:00
Jack Franklin
9522f80116
chore: create common directory (#6042)
These files will be used by both the web and node versions of Puppeteer.
Another name for this might be "core" but I don't want to cause
confusion with the puppeteer-core package that we publish at the moment.
2020-06-18 15:53:23 +01:00
Jack Franklin
90b0934f85
chore: create node directory for Node-only files (#6041)
This is another step towards making Puppeteer agnostic of environment
and being able to run in Node or a browser.

The files in the `node` directory are ones that would only be needed in
the Node build - e.g. the code that downloads and launches a local
browser instance.

The long term vision here is to have three folders:

* node - Node only code
* web - Web only code
* common - code that is shared

But rather than do that in one PR I'm going to split it up to make it
easier to review and deal with.
2020-06-18 13:49:59 +01:00
Mathias Bynens
f1ec6a3df0
chore: update references to branch names (#6022) 2020-06-15 17:34:16 +02:00
Jack Franklin
b659969a38
chore: migrate away from Node's EventEmitter (#5979) 2020-06-15 11:52:19 +01:00
Jack Franklin
8a099a0c2c
docs: replace @return with @returns (#6006)
The former is not understood by TSDoc.
2020-06-12 12:38:24 +02:00
Jack Franklin
0b3d52a70e
feat(new-docs): add TSDoc comments to Accessibility (#5971)
* feat(new-docs): add tsdoc to `Accessibility`
2020-06-05 15:20:11 +01:00
Jack Franklin
309d8115c3
chore: Revert Mitt due to breaking changes (#5952)
Replacing the Node EventEmitter with Mitt caused more problems than
anticipated for end users due to the API differences and the amount of
people who relied on the EventEmitter API. In hindsight this clearly
should have been explored more and then released as a breaking v4.

This commit rolls us back to the built in Node EventEmitter library
which we can release to get everyone back on stable builds. We can then
consider our approach to migrating to Mitt and when we do do that we can
release it as a breaking change and properly document the migration
strategy and approach.
2020-06-02 09:32:02 +01:00
Jack Franklin
b874cacaef
chore: rename Worker to WebWorker (#5941)
To avoid TS name conflicts.
2020-05-29 12:57:54 +01:00
Jack Franklin
1d4d25a0f3
Use Mitt as the Event Emitter (#5907)
* chore: migrate to Mitt as the EventEmitter

This commit moves us to using Mitt [1] for the event emitter in
Puppeteer. This removes our dependency to Node's EventEmitter which is
part of a larger stream of work to enable a Puppeteer-web version that
doesn't depend on Node.

There are no large breaking changes as we support the main methods that
EventEmitter had, but it also provides some methods that Puppeteer
didn't use. Technically end users could depend on this but it's
unlikely.

[1]: https://github.com/developit/mitt
2020-05-29 09:59:26 +01:00
Jack Franklin
8e8a9df3dd
chore: rename Request class to HTTPRequest (#5934)
It conflicts with an inbuilt TypeScript `Request` type so can cause
confusion when in TS land. Note: `Response.ts` and `Worker.ts` also
suffer from this; PRs to rename them are incoming.
2020-05-29 09:38:40 +01:00
Jack Franklin
9737059400
chore: remove doclint generate_types code (#5932)
This script generated an `index.d.ts` file but that file was never
commited to git nor included in Puppeteer when we ship. As of right now
people who want TS types can install from the DefinitelyTyped repo and
we are working on shipping types from Puppeteer itself.

Therefore this script is not adding any value and can be removed.
2020-05-28 15:55:14 +01:00
Mathias Bynens
7eab7f8dd9
feat(api): add page.emulateVisionDeficiency(type) (#5901)
Design doc: https://goo.gle/devtools-cvd
2020-05-26 17:14:20 +02:00
Jack Franklin
c6d01c950e
chore: extract BrowserRunner into its own module (#5850)
* chore: extract `BrowserRunner` into its own module

`src/Launcher.ts` is large and hard to work in. It has multiple objects
defined in it:

* ChromeLauncher
* FirefoxLauncher
* BrowserRunner
* Launcher

This change moves BrowserRunner into its own module. More refactorings
like this will follow but this is the first step.
2020-05-12 16:30:13 +01:00
Jack Franklin
4fdb1e3cab
chore: add Prettier (#5825) 2020-05-07 12:54:55 +02:00
Jack Franklin
ae7483d5cf
chore: remove src/externs.d.ts (#5811)
* chore: remove src/externs.d.ts

It defined global types that we don't want to use, and instead we move
to using interfaces that we import and reference just like with any
other interface.

This means other than Protocol (which I think is fine to leave as is),
there are no other magic global types and you have to import any types
or interfaces that you want.
2020-05-06 14:23:07 +01:00
Jack Franklin
de4f08dc52
chore: migrate src/Page.js to TypeScript (#5809)
* chore: migrate src/Page.js to TypeScript

The final one! This is a huge file and needs to be split up and tidied,
but for now I've left all the definitions in place and converted types
accordingly.

There's some additional tidying we can do now every `src` file is TS,
but I'll leave that for another PR to avoid this one getting any bigger.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-05-05 13:53:22 +01:00
Jack Franklin
890c215142
chore: migrate src/Puppeteer to TypeScript (#5789)
* chore: migrate src/Puppeteer to TypeScript.

* fix api js
2020-05-05 09:36:44 +01:00
Jack Franklin
ec91ecaf0b
chore: migrate src/Launcher to TypeScript (#5775) 2020-04-30 13:45:58 +01:00
Mathias Bynens
541281b9f3
chore: fix doclint issues (#5784) 2020-04-30 12:58:51 +02:00
Jack Franklin
8654d630ad
chore: migrate src/NetworkManager to TypeScript (#5774) 2020-04-30 11:15:27 +01:00
Jack Franklin
8a5008e30b
chore: migrate src/FrameManager to TypeScript (#5773) 2020-04-29 13:28:16 +02:00
Jack Franklin
06d62c0165
chore: migrate src/Browser to TS (#5761) 2020-04-28 14:26:37 +02:00
Jack Franklin
1358b45fca
chore: migrate src/LifecycleWatcher (#5734) 2020-04-27 10:03:33 +01:00
Jack Franklin
18238280df
chore: migrate src/Tracing to TypeScript (#5723) 2020-04-23 13:51:48 +02:00
Jack Franklin
133abb07cf
chore: migrate src/Input to typescript (#5710)
* chore: migrate src/Input to typescript

This moves `Keyboard`, `Mouse` and `Touchscreen` to TypeScript. We gain
some nice TS benefits here; by creating a type for all the keycodes we
support we can type the input args as that rather than `string` which
will hopefully save some users some debugging once we ship our TS types
in a future version.

* Remove from externs file

* Update utils/doclint/check_public_api/index.js

Co-Authored-By: Mathias Bynens <mathias@qiwi.be>

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-22 15:44:04 +01:00
Jack Franklin
8d5d76ed70
chore: migrate src/JSHandle to TS (#5703)
* chore: migrate src/JSHandle to TS

There's a few TODOs in here that all depend on typing the
`ExecutionContext.evaluateHandle` properly so that you can properly
declare what types you're expecting back. Once I've done that file (it's
next on my list) I will loop back and improve the types here, fixing
these TODOs.

* Fix doclint for {}
2020-04-21 12:11:06 +01:00
Jack Franklin
e3922ea1f3
chore: enforce consistent spacing around object curlys (#5700)
The codebase was incredibly inconsistent with the use of spacing around
curly braces, e.g.:

```
// this?
const a = {b: 1}
// or?
const a = { b: 1 }
```

This extended into import statements also. Google's styleguide is no
spacing, so we're going with that.
2020-04-21 10:40:04 +01:00
Jack Franklin
a614bc45aa
chore: migrate src/Connection to TypeScript (#5694)
* chore: migrate `src/Connection` to TypeScript

This commit migrates `src/Connection` to TypeScript. It also changes its
exports to be ESM because TypeScript's support for exporting values to
use as types via CommonJS is poor (by design) and so rather than battle
that it made more sense to migrate the file to ESM.

The good news is that TypeScript is still outputting to `lib/` as
CommonJS, so the fact that we author in ESM is actually not a breaking
change at all.

So going forwards we will:

* migrate TS files to use ESM for importing and exporting
* continue to output to `lib/` as CommonJS
* continue to use CommonJS requires when in a `src/*.js` file

I'd also like to split `Connection.ts` into two; I think the
`CDPSession` class belongs in its own file, but I will do that in
another PR to avoid this one becoming bigger than it already is.

I also turned off `@typescript-eslint/no-use-before-define` as I don't
think it was adding value and Puppeteer's codebase seems to have a style
of declaring helper functions at the bottom which is fine by me.

Finally, I updated the DocLint tool so it knows of expected method
mismatches. It was either that or come up with a smart way to support
TypeScript generics in DocLint and given we don't want to use DocLint
that much longer that didn't feel worth it.

* Fix params being required
2020-04-21 09:20:25 +01:00
Jack Franklin
3e4c8c9d0d
chore(typescript): migrate src/Dialog (#5639)
This PR changes `src/Dialog.js` to `src/Dialog.ts` and rewrites
accordingly. Most of the changes are straight forward; the only
interesting one from a TS point of view is the `DialogType` enum. I
expose it again as `Dialog.Type` to avoid a breaking change.

This PR also exposed some bugs with our ESLint TypeScript settings and
applying the overrides, so I fixed those too.

I also updated our DocLint tool to work on TS source files over JS lib
files if they exist. This is the minimal change to keep the existing doc
system working as we're working on moving away from this system longer
term.
2020-04-16 14:59:28 +01:00
Jack Franklin
a9f6a266b9
chore: Log reminder about tsc if DocLint fails locally (#5652)
I lost some time debugging before realising that I needed to run tsc. I
don't really want to put `npm run tsc` before this command else we'll
run tsc multiple times on each CI build, so I think this message is
suitable.

Travis defines `process.env.TRAVIS` and if that exists we don't want to
log this as on CI we're guaranteed to have an up to date `lib/`
directory.
2020-04-16 14:40:04 +01:00
Jack Franklin
88d843d4f0
feat(TypeScript): move DeviceDescriptors to TS (#5595)
This commit moves `src/DeviceDescriptors` to be authored in TypeScript. This file was chosen due to its simplicity so that we can focus on getting a mixed JS/TS codebase playing nicely before migrating the more complex files.

The file itself was a bit odd: although the array of devices was exported via `module.exports` that was never referenced by any consumers; each device was also exported via `module.exports[name] = device` and that is how it's consumed. The Puppeteer docs suggest using it like so:

```js
puppeteer.devices['iPhone 6']
```

So instead of exporting the array and then setting a bunch of properties on that, we instead define the array and export an object of keys where each key is a device. This is a breaking change (see the footer for details).

Rather than export an object I'd much rather export a Map, but that would be a larger breaking change and I'm keen to avoid those for the time being.

Note that we have to use special TypeScript specific syntax for the export that enables it to work in a CommonJS codebase [1] but again I'd rather this than move to ESM at this time. TypeScript still outputs CommonJS into `lib/` as you would expect.

BREAKING CHANGE: We no longer export an array of devices, so any users relying on doing:

```js
puppeter.devices.forEach(...)
```

…will now see a breakage. The fix is to use `Object.{keys/entries/values}` to iterate instead.

[1]: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
2020-04-14 11:55:29 +02:00
Jack Franklin
0bcc5a7ad8
chore: migrate remaining tests to Mocha (#5616)
This commit updates all the non-Puppeteer unit tests to run using Mocha and then deletes the custom test runner framework from this repository. The documentation has also been updated.
2020-04-09 20:12:32 +02:00
Jack Franklin
efe561e112
chore: fix DocLint method diffing (#5594)
Our logic around missing methods wasn't quite right; if there is no set of missing methods for a class it _is_ an error and we still need to report it, we don't want to `continue`.
2020-04-06 12:36:28 +02:00
Jack Franklin
4ee2c43f06
chore: fix Page.emulateMedia doclint failure (#5584)
This is expected as we now alias `emulateMedia` in `index.js` which isn't a file checked by DocLint. We alias there to avoid having the function overriden by the `asyncInstallHooks` code.

This commit updates doclint to know about methods that we expect it will find are missing and in that case just skip over them. We should only do this for methods where we plan to deprecate them or we have to define them in an odd way to work around some problem (and if that's the case long term we should fix that problem so we can define them as normal).

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-06 10:38:05 +02:00
Jack Franklin
88446df724
chore: fix missed src/ vs lib/ documentation (#5591)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-06 10:32:42 +02:00
Jack Franklin
6522e4f524
chore: Use expect for assertions (#5581)
Rather than use our own custom expect library, we can use expect from npm [1], which has an API almost identical to the one Puppeteer has, but with more options, better diffing, and is used by many in the community as it's the default assertions library that comes with Jest.

It's also thoroughly documented [2].

[1]: https://www.npmjs.com/package/expect
[2]: https://jestjs.io/docs/en/expect
2020-04-03 13:22:55 +02:00
Jack Franklin
4b0fd8bc30
chore: upgrade to TypeScript 3.7 (#5562)
TypeScript seems to struggle to understand `Promise.all` when the items in the array return different types. If we were authoring in TS we could fix this with TS generics (`Promise.all<OurTypeHere>(...)`) but for now we can typecast the result. We'll fix this properly when we author in TS.
2020-03-31 18:42:32 +02:00