Commit Graph

73 Commits

Author SHA1 Message Date
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
232def0dcf
chore: rename Response to HTTPResponse (#5940)
To avoid any conflicts with the TS `Response` type.
2020-05-29 11:49:30 +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
musou1500
a2ba6f0abb
feat: recognize webviews as regular pages (#5905) 2020-05-29 10:46:44 +02: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
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
Henrik Skupin
6cfe142af1
Don't use expect within Promises (#5466) (#5473)
* Don't use expect within Promises (#5466)

If a call to expect fails within a Promise it will not
be resolved, and causing the test to crash.

The patch aligns the code similar to what is used by all
the other tests.
2020-05-26 09:22:11 +01:00
Jack Franklin
dfb2e6056b
chore: stop Protocol types being globally available (#5899)
We should import them just like any other module. This commit makes that
change. It does not change any behaviours or the types themselves.

EXPECTED_PROTOCOL_DIFF as we're updating the structure of it.
2020-05-21 17:04:05 +01:00
Islam ElHakmi
caaf4d2086
fix: support async functions as an argument for waitForFunction (#5682) 2020-05-19 09:09:31 +02:00
Michal TOMA
a17bd89fb9 feat: add securityDetails.subjectAlternativeNames() #5628 (#5881)
Co-authored-by: Michal TOMA <michaltoma2205@gmail.com>
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>

Fixes #5625. Closes #5628.
2020-05-18 12:59:57 +02:00
Alex Rudenko
e8232890a4
feat(chromium): roll Chromium to r756035 (#5879)
This corresponds to Chromium 83.0.4103.0.

This roll includes:

- Enable SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure https://crrev.com/c/2122809
2020-05-18 11:06:42 +02:00
Christian Bromann
39f1b13449
chore: extract Request and Response into its own module (#5861)
* chore: extract `Request` and `Response` into its own module
2020-05-13 14:57:21 +01:00
Christian Bromann
b510c354c7
chore: fetch Firefox from JSON source instead of RegExp (#5864)
Fetch Firefox from https://product-details.mozilla.org/1.0/firefox_versions.json.

Fixes #5742.
2020-05-13 15:48:39 +02:00
Christian Bromann
69c38fc2d0
chore: extract ConsoleMessage and FileChooser into its own module (#5856)
* chore: extract `ConsoleMessage` and `FileChooser` into its own module
2020-05-13 11:30:29 +01:00
Christian Bromann
5f42547c9d
chore: extract SecurityDetails into its own module (#5858)
* chore: extract `SecurityDetails` into its own module
2020-05-13 10:32:46 +01: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
b38bb4334f
Warn when given unsupported product name. (#5845)
* Warn when given unsupported product name.

Fixes #5844.

This change means when a user launches Puppeteer with a product name
that is not supported (which at the time of this commit means it's not
`firefox` or `chrome) we will warn them about it.

Decided on just a warning vs an error because the current behaviour is
that we fallback to launching Chrome and I don't think this warrants a
breaking change.
2020-05-12 10:30:24 +01:00
Jack Franklin
5343c7a18f
chore: private-ise src/Accessibility.ts (#5832)
Now the first pass of migrating to TypeScript is complete I'm going
through the src files one by one to tidy up the public/private
interfaces.

Puppeteer used an underscore convention to denote privacy but violates
this in some places; we should be strict with TypeScript's `public` and
`private` keywords instead.

This means we'll get nice TS errors if you try to refer to a private
method/variable, and means when we swap to generating our TS docs the
tooling knows what method(s) are public and therefore need to be
documented vs private internals that don't.
2020-05-07 17:26:05 +01:00
Jack Franklin
49ce65943c
chore: remove src/TaskQueue (#5826)
* chore: Remove src/TaskQueue

The only place it's used is in `src/Page.ts` to have a chain of
screenshot promises. Rather than initialize a task queue in `Browser`
and pass it through a chain of constructors we instead move the class
into `src/Page` and define it inline.

In the future we might want to create a helpers folder to contain small
utilities like that (`src/Page.ts` is already far too large) but I'm
leaving that for a future PR.

`TaskQueue` isn't documented in `api.md` so I don't think this is a
breaking change.

I updated the type of `screenshot()` to return `Promise<string | Buffer
| void>` because if a promise rejects it's silently swallowed. I'd like
to change this behaviour but one step at a time. This type only had to
change as now we type the screenshot task queue correctly rather than
using `any` which then exposed the incorrect `screenshot()` types.
2020-05-07 14:49:42 +01:00
Jack Franklin
4fdb1e3cab
chore: add Prettier (#5825) 2020-05-07 12:54:55 +02:00
Avi Vahl
70d5c7ffe9
fix: remove node@14 specific extract timeout (#5816)
closes #5719

Original stream.pipeline issue has been fixed in Node 14.1.0 and above.

Meanwhile, the workaround itself caused timout failures in many CI Node 14 runs, as reported in #5719.

Removed it, as it's no longer needed, and actually blocks consumers from adding CI testing on Node 14.
2020-05-07 09:46:53 +01: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
d8d1f6ff7c
chore: migrate src/api.js to TypeScript (#5808) 2020-05-05 10:59:07 +02: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
Paul Lewis
4a47867a24
feat: add support for string-based custom queries (#5753) 2020-04-30 12:45:52 +01:00
Jack Franklin
8654d630ad
chore: migrate src/NetworkManager to TypeScript (#5774) 2020-04-30 11:15:27 +01:00
Jack Franklin
af2e45820f
chore: migrate src/Target to TypeScript (#5771) 2020-04-29 15:18:09 +01:00
Jack Franklin
8a5008e30b
chore: migrate src/FrameManager to TypeScript (#5773) 2020-04-29 13:28:16 +02:00
Jack Franklin
c5c97b07b5
chore: remove DOMWorld definition from externs.d.ts (#5767)
Missed in the initial work to migrate DOMWorld to TypeScript.
2020-04-28 18:45:55 +02:00
Jack Franklin
da6e6c00e5
chore: migrate src/EmulationManager to TypeScript (#5766) 2020-04-28 18:45:34 +02:00
Jack Franklin
01578446fa
chore: migrate src/DOMWorld to TypeScript (#5764) 2020-04-28 15:35:43 +01:00
Jack Franklin
d69fbb9974
chore: Enforce array type styles in TypeScript (#5765)
This change enforces how we type arrays, e.g. choosing between:

* `string[]`
* `Array<string>`

I've gone for the `array-simple` option [1] which enforces that:

* primitive types and type references use `X[]`
* complex types use `Array<X>`

For example, we'd type an array of strings as `string[]`, but an array
of a union type as `Array<SomeUnionType>`.

[1]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
2020-04-28 15:06:43 +01:00
Jack Franklin
1ccfbcb684
chore: enforce naming of errors in catch blocks (#5763) 2020-04-28 15:16:28 +02:00
Jack Franklin
06d62c0165
chore: migrate src/Browser to TS (#5761) 2020-04-28 14:26:37 +02:00
Jack Franklin
e03113e38b
chore: Update protocol.d.ts (#5760) 2020-04-28 11:31:34 +01:00
Jack Franklin
5e2a029e44
chore: use Node's promisify function (#5748)
Node's promisify function and the TS types for it give much better type understanding when wrapping a function in `promisify`. This change means we don't maintain our own implementation and our own (sub-par) types and rather lean on the tested and thorough @types/node version instead.
2020-04-27 12:51:59 +02:00
Jack Franklin
1b9d9e9cc0
chore: log useful error for Node v14 breakage (#5732)
* chore: Useful error for Node v14 breakage

There is currently a bug with extract-zip and Node v14.0.0 that
causes extractZip to silently fail:
https://github.com/puppeteer/puppeteer/issues/5719

Rather than silenty fail if the user is on Node 14 we instead
detect that and throw an error directing the user to that bug. The
rejection message below is surfaced to the user in the command line.

The issue seems to be in streams never resolving so we wrap the call in
a timeout and give it 100ms to resolve before deciding on an error. If
the user is on Node < 14 we maintain the behaviour we had before this
patch.

Here's how this change impacts the output on Node 14 and Node 10:

Node 10:

```
npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
Chromium (737027) downloaded to /Users/jacktfranklin/src/puppeteer/.local-chromium/mac-737027
```

---

Node 14 without this patch:

```
npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
```

Note that whilst it doesn't error, it doesn't complete the install. We
don't get the success message that we saw above in the Node 10 install.

---

Node 14 with this patch:

```npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
ERROR: Failed to set up Chromium r737027! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
Puppeteer currently does not work on Node v14 due to an upstream bug. Please see https://github.com/puppeteer/puppeteer/issues/5719 for details.
```

The explicit message should save users a good amount of debugging time.
2020-04-27 11:38:17 +01:00
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
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