Commit Graph

1860 Commits

Author SHA1 Message Date
Jack Franklin
1358b45fca
chore: migrate src/LifecycleWatcher (#5734) 2020-04-27 10:03:33 +01:00
Paul Lewis
79e82e5b65
fix: make uploadFile throw for non-existent files (#5733) 2020-04-24 13:36:46 +02:00
Jack Franklin
1a4e260458
chore: migrate src/BrowserFetcher to TypeScript (#5727)
* chore: migrate src/BrowserFetcher to TypeScript
2020-04-24 08:57:53 +01:00
Jack Franklin
8509f4660e
chore: migrate src/Accessibility to TypeScript (#5726) 2020-04-23 15:35:03 +01:00
Jack Franklin
930cc32baf
chore: migrate src/Errors to TypeScript (#5725) 2020-04-23 13:53:47 +02:00
Jack Franklin
30aff827ea
chore: migrate src/Events to TypeScript (#5724) 2020-04-23 13:52:09 +02:00
Jack Franklin
18238280df
chore: migrate src/Tracing to TypeScript (#5723) 2020-04-23 13:51:48 +02:00
Vikram
3050196d81
fix: update clipboard read write permissions after upstream change (#5721)
Upstream change: https://chromium-review.googlesource.com/c/chromium/src/+/1895749

Fixes #5720.
2020-04-23 11:41:09 +02:00
Mathieu 'p01' Henri
0731049f86
chore: update pngjs to 5.0.0 and jpeg-js to 0.3.7 (#5676) 2020-04-23 11:38:00 +02:00
munrocket
ddb8ba1baf
chore: tidy up and de-duplicate Travis CI config (#5716) 2020-04-23 09:29:37 +01:00
Jack Franklin
9d297f0827
chore: Bump version to 3.0.1-post (#5717) 2020-04-22 16:07:57 +01:00
Jack Franklin
be8f8a29a9
chore: Add macOS to Travis CI (#5708)
Runs TypeScript and the unit tests on an OS X build.
2020-04-22 15:44:24 +01: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
11bc5a6450
chore: migrate src/Worker to typescript (#5715) 2020-04-22 15:43:45 +01:00
Jack Franklin
feec588f95
chore: add test for npm package installing correctly (#5714)
* chore: add test for npm package installing correctly

This command packs up the module and installs it again to check we're
correctly bundling everything we need to allow users to do a fresh
install.

* install realpath
2020-04-22 15:33:36 +01:00
Jack Franklin
1615c9c9d5
chore: add install.js to files for publishing (#5712) 2020-04-22 12:16:51 +01:00
Jack Franklin
6029fdd618
chore: mark version v3.0.1 (#5709) 2020-04-22 11:10:04 +01:00
Jack Franklin
29ebd0bb3e
chore: migrate src/ExecutionContext (#5705)
* chore: migrate src/ExecutionContext to TypeScript

I spent a while trying to decide on the best course of action for
typing the `evaluate` function.

Ideally I wanted to use generics so that as a user you could type
something like:

```
handle.evaluate<HTMLElement, number, boolean>((node, x) => true, 5)
```

And have TypeScript know the arguments of `node` and `x` based on those
generics. But I hit two problems with that:

* you have to have n overloads of `evaluate` to cope for as many number
of arguments as you can be bothered too (e.g. we'd need an overload for
1 arg, 2 args, 3 args, etc)
* I decided it's actually confusing because you don't know as a user
what those generics actually map to.

So in the end I went with one generic which is the return type of the
function:

```
handle.evaluate<boolean>((node, x) => true, 5)
```

And `node` and `x` get typed as `any` which means you can tell TS
yourself:

```
handle.evaluate<boolean>((node: HTMLElement, x:  number) => true, 5)
```

I'd like to find a way to force that the arguments after the function do
match the arguments you've given (in the above example, TS would moan if
I swapped that `5` for `"foo"`), but I tried a few things and to be
honest the complexity of the types wasn't worth it, I don't think.

I'm very open to tweaking these but I'd rather ship this and tweak going
forwards rather than spend hours now tweaking. Once we ship these
typedefs and get feedback from the community I'm sure we can improve
them.
2020-04-22 10:33:44 +01:00
Sam
69bfa80084
Update api.md (#5706) 2020-04-22 09:41:49 +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
42893d8755
chore: migrate src/coverage to TypeScript (#5702) 2020-04-21 11:45:29 +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
3600f2f99b
chore: migrate src/helpers.ts to ESM (#5699)
* chore: migrate src/helpers.ts to ESM

Doing this means we can avoid the global `types.d.ts` file and export
the interface via ESM instead.

I would ideally like to rewrite the helper module so that it doesn't
export all the functions under the `helper` namespace, but I'll leave
that for a separate PR to keep mechanical changes to one per PR and
easier to review.
2020-04-21 10:22:20 +01:00
Jack Franklin
f13c30a9ec
chore: migrate src/USKeyboardLayout to typescript (#5695)
* chore: migrate `src/USKeyboardLayout` to typescript

Don't think we need to expose the interface type for the keycodes so
I've left it local for now.

* retry windows unit tests
2020-04-21 10:21:45 +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
376d234ed1
chore: migrate src/WebSocketTransport to TypeScript (#5696) 2020-04-21 08:45:52 +02:00
Stano Bo
5c839f5e48
chore(docker): add missing libgbm1 dependency (#5693) 2020-04-20 17:28:18 +02:00
Jack Franklin
e7a32a8851
chore: migrate src/pipetransport to typescript (#5692)
* chore: migrate `src/pipetransport` to typescript

Hit one bump in the fact that I want to share an interface across files.
TypeScript only lets you import/export these if you're using ESM, not
CommonJS. So the two options are:

- Migrate to ESM on a per file basis as we do this migration. This won't
affect the output as we output as CommonJS.
- Create a global `types.d.ts` file that we'll use and then migrate to
ESM after.

Right now I've gone for the second option in order to not introduce more
changes in one go. But if we end up finding we have lots of
interfaces/types/etc that we want modules to expose, we might decide
slowly introducing ESM might be a better way forwards.

* Update src/types.d.ts

Co-Authored-By: Mathias Bynens <mathias@qiwi.be>
2020-04-20 15:05:58 +01:00
Jack Franklin
4134b540ca
chore: migrate src/helper to typescript (#5689)
This PR migrates the helper module to TypeScript. It's a bit of a bigger
change than others because I decided to move away from the helper class
with static methods and move towards a simpler set up where the module
is a bunch of functions. I still expose them under the `helper`
namespace to avoid this being a big change - we can update that later
when we migrate to ESM.

We do have to do some unfortunate wrangling of the promisify function.
Ideally I'd like to rely on the Node one (and the type defs) but that
doesn't work in Browserify land. I've stuck with the promisify in
`helper.ts` but pulled it into its own module to enable me to leave a
comment clarifying why we use it and the context. We can solve this with
a better web bundling story but that work is lower priority right now
than getting the `src/` directory into TypeScript.
2020-04-20 12:02:32 +01:00
Jack Franklin
c32b049e18
chore: delete src/MultiMap (#5690)
Went to migrate to TypeScript but a grep of the codebase for `MultiMap` reveals that nothing requires it :)
2020-04-20 12:37:27 +02:00
Jack Franklin
6638a24346
chore: migrate src/timeoutsettings to typescript (#5691) 2020-04-20 11:32:08 +01:00
atlanteh
ad6c57aeb9
docs: fix DeviceDescriptor link (#5683) 2020-04-20 09:20:52 +02:00
Jack Franklin
c4fe4e46c2
chore(ci): re-enable tests on Windows (#5637)
* chore: Add Windows to Travis

This commit runs the unit tests on Windows.

There are two tests failing on Windows that we skip.

I spoke to Mathias B and we agreed to
defer debugging this for now in favour of getting tests running on
Windows. But we didn't want to ignore it forever, hence giving the test
a date at which it will start to fail.
2020-04-17 14:27:50 +01:00
Jack Franklin
49ca00f16a
docs(contributing): update testing section (#5657)
This was missed in the Mocha migration.

The options I've removed from the docs were removed from the code; I didn't think it worth implementing them in Mocha land until we definitely needed them. So shout if you miss any of the options!

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-17 11:33:47 +02:00
Jack Franklin
1a57ba22a8
chore: Migrate TaskQueue to TypeScript (#5658)
This is a simple module but took a bit of work because:

* It wraps a Promise that can return basically anything. In a pure TS
codebase we'd solve these with generics, so you could do `new
TaskQueue<T>` where `T` will be what's returned from the queue, but
because we're calling that from JS we can't yet. I've left a TODO and
once we migrate the call sites to TS we can do a much better job than
the `void | any` type I've gone with for now.

* It was used in typedefs via `Puppeteer.TaskQueue`. I've removed that
entry from `externs.d.ts` in favour of importing it and using the type
directly. This does mean that we have imports that ESLint doesn't
realiase are actually used but I think this is better than maintaining
`externs.d.ts`.
2020-04-17 11:32:56 +02:00
Jack Franklin
ef3befa2e6
chore: manage published files via files option (#5659)
Rather than a denylist (`.npmignore`) we can instead use an allowlist
via the `files` option in `package.json`. This makes it much harder to
accidentally include files or folders in the build as you have to
explicitly list the files that will be included.

Fixes #5648.
2020-04-17 11:32:25 +02:00
Ryō Igarashi
35fc65492d
docs: change the Alpine Docker example to use env instead of launch option (#5666) 2020-04-17 11:30:26 +02:00
Jack Franklin
20c22ad9ad
chore: fix installing from GitHub URL (#5669)
The change to the install script to require TypeScript works fine when
installing from npm (because on npm the `lib` directory with the
compiled code already exists) but doesn't if you install from a GitHub
URL. By default it seems npm uses the `files` list when you install from
GitHub which means it's missing a bunch of files that we need to
compile.

Additionally by default when installing from a GitHub URL npm doesn't
install the dependencies which is an issue for us when we need to
compile TypeScript.

The fix is to create a `prepare` script that runs TypeScript if
required. From the npm docs [1]:

> `prepare`: Run both BEFORE the package is packed and published, on
> local npm install without any arguments, and when installing git
> dependencies

And from the npm docs on install [2], it confirms that if a package has
a `prepare` script it is run when installing from GitHub:

> As with regular git dependencies, dependencies and devDependencies
> will be installed if the package has a prepare script, before the
> package is done installing.

Despite having the `prepare` script we still need the TypeScript check
in `install.js` to satisfy the 3rd scenario below where we need to force
a compile:

* If I'm a user installing `puppeteer@X` from npm, the module is
published with the `lib/` directory of compiled code, so I'm set.
* If I'm a user installing Puppeteer from GitHub, the `prepare` script
will run TypeScript for me so I'm set.
* If I'm a developer working on Puppeteer, the `prepare` script also
runs but _after_ `npm install` which means `install.js` fails as it
requires `./lib/helper.js`. So in `install.js` we call
`compileTypeScriptIfRequired` to catch this case.

[1]: https://docs.npmjs.com/misc/scripts
[2]: https://docs.npmjs.com/cli/install

Co-authored-by: Mathias Bynens <mathias@qiwi.be>

Fixes #5660.
2020-04-17 11:29:40 +02:00
Mathias Bynens
46ef9f79ca
docs(troubleshooting): list libgbm-dev dependency (#5667)
Fixes #5661.
2020-04-17 10:14:18 +02:00
Paul Lewis
532ae573d2
fix(JSHandle): Fixes file upload (#5655)
This PR returns to using `DOM.setFileInputFiles`, but with some additional fixes and checks for events and multiple files.
2020-04-16 16:22:52 +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
Mathias Bynens
37bae17038
docs(contributing): update npm dist tags section (#5650)
The chrome-stable tags haven't been updated in a long time. This patch updates the documentation to reflect this reality.
2020-04-16 12:08:59 +02:00
Mathias Bynens
80348dc574
chore: bump version to v3.0.0-post (#5649) 2020-04-16 11:23:26 +02:00
Changhao Han
6760b9225e
chore: mark version v3.0.0 (#5642)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-16 10:43:12 +02:00
Changhao Han
3387aab37f feat(chromium): roll Chromium to r737027 (#5644)
This corresponds to Chromium 81.0.4044.0.

This roll includes:

- [DevTools] Add Cookie Priority support to CDP
  https://chromium-review.googlesource.com/c/chromium/src/+/1959029
- Reject cookies with empty names and values
  https://chromium-review.googlesource.com/c/chromium/src/+/1982549
2020-04-16 09:54:00 +02:00
Mathias Bynens
c5df4902cb
docs(readme): update cross-browser FAQ (#5634) 2020-04-15 16:46:01 +02:00
Maja Frydrychowicz
35989a78ba
fix: set revision based on PUPPETEER_PRODUCT (#5643) 2020-04-15 13:30:42 +02:00
Maja Frydrychowicz
d817ae5a4b
fix: update preferred revision after Launcher is created (#5640)
Fixes an edge case where Puppeteer looked for a Chromium revision when launching Firefox.

Allow appropriate Launcher to be instantiated when calling `Puppeteer.connect`.

Add an example of running Firefox.
2020-04-14 18:42:48 +02:00
Jack Franklin
df8125056a
chore: update ws library (#5638)
Updates `ws` and `@types/ws` to version 7.

The breaking changes in version 7 are not ones that impact this project
[1].

[1]: https://github.com/websockets/ws/releases/tag/7.0.0
2020-04-14 15:13:38 +01:00