Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: puppeteer/puppeteer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v9.0.0
Choose a base ref
...
head repository: puppeteer/puppeteer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.1.0
Choose a head ref
  • 6 commits
  • 8 files changed
  • 4 contributors

Commits on Apr 21, 2021

  1. Copy the full SHA
    0fa0a34 View commit details

Commits on Apr 22, 2021

  1. Copy the full SHA
    49a54cf View commit details

Commits on Apr 27, 2021

  1. fix: change rm -rf to rimraf (#7168)

    Currently, `npm clean-lib` fails on windows with `cmd` because it does not now about `rm`.
    This change uses the already installed `rimraf` to do the job instead.
    jschfflr authored Apr 27, 2021
    Copy the full SHA
    ad6b736 View commit details

Commits on May 3, 2021

  1. chore: disable flaky test on Firefox

    Issue: #7182
    jschfflr authored and mathiasbynens committed May 3, 2021
    Copy the full SHA
    a293b96 View commit details
  2. feat: add option to filter targets (#7192)

    * feat: add option to filter targets
    
    Co-authored-by: Mathias Bynens <mathias@qiwi.be>
    jschfflr and mathiasbynens authored May 3, 2021
    Copy the full SHA
    ec3fc2e View commit details
  3. Copy the full SHA
    1d473bc View commit details
Showing with 89 additions and 22 deletions.
  1. +12 −0 CHANGELOG.md
  2. +11 −11 README.md
  3. +3 −1 docs/api.md
  4. +2 −2 package.json
  5. +20 −3 src/common/Browser.ts
  6. +8 −2 src/common/BrowserConnector.ts
  7. +2 −1 test/click.spec.ts
  8. +31 −2 test/launcher.spec.ts
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [9.1.0](https://github.com/puppeteer/puppeteer/compare/v9.0.0...v9.1.0) (2021-05-03)


### Features

* add option to filter targets ([#7192](https://github.com/puppeteer/puppeteer/issues/7192)) ([ec3fc2e](https://github.com/puppeteer/puppeteer/commit/ec3fc2e035bb5ca14a576180fff612e1ecf6bad7))


### Bug Fixes

* change rm -rf to rimraf ([#7168](https://github.com/puppeteer/puppeteer/issues/7168)) ([ad6b736](https://github.com/puppeteer/puppeteer/commit/ad6b736039436fcc5c0a262e5b575aa041427be3))

## [9.0.0](https://github.com/puppeteer/puppeteer/compare/v8.0.0...v9.0.0) (2021-04-21)


22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

<img src="https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png" height="200" align="right">

###### [API](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/main/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md)
###### [API](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/main/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md)

> Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). Puppeteer runs [headless](https://developers.google.com/web/updates/2017/04/headless-chrome) by default, but can be configured to run full (non-headless) Chrome or Chromium.
@@ -41,7 +41,7 @@ npm i puppeteer
# or "yarn add puppeteer"
```

Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, or to download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#environment-variables).
Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, or to download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#environment-variables).

### puppeteer-core

@@ -66,7 +66,7 @@ Note: Prior to v1.18.1, Puppeteer required at least Node v6.4.0. Versions from v
Node 8.9.0+. Starting from v3.0.0 Puppeteer starts to rely on Node 10.18.1+. All examples below use async/await which is only supported in Node v7.6.0 or greater.

Puppeteer will be familiar to people using other browser testing frameworks. You create an instance
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#).
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#).

**Example** - navigating to https://example.com and saving a screenshot as _example.png_:

@@ -91,7 +91,7 @@ Execute script on the command line
node example.js
```

Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#pagesetviewportviewport).
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#pagesetviewportviewport).

**Example** - create a PDF.

@@ -118,7 +118,7 @@ Execute script on the command line
node hn.js
```

See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#pagepdfoptions) for more information about creating pdfs.
See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#pagepdfoptions) for more information about creating pdfs.

**Example** - evaluate script in the context of the page

@@ -153,7 +153,7 @@ Execute script on the command line
node get-dimensions.js
```

See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`.
See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`.

<!-- [END getstarted] -->

@@ -163,7 +163,7 @@ See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/

**1. Uses Headless mode**

Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#puppeteerlaunchoptions) when launching a browser:
Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#puppeteerlaunchoptions) when launching a browser:

```js
const browser = await puppeteer.launch({ headless: false }); // default is true
@@ -179,7 +179,7 @@ pass in the executable's path when creating a `Browser` instance:
const browser = await puppeteer.launch({ executablePath: '/path/to/Chrome' });
```

You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#puppeteerlaunchoptions) for more information.
You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#puppeteerlaunchoptions) for more information.

See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/master/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users.

@@ -191,7 +191,7 @@ Puppeteer creates its own browser user profile which it **cleans up on every run

## Resources

- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md)
- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md)
- [Examples](https://github.com/puppeteer/puppeteer/tree/main/examples/)
- [Community list of Puppeteer resources](https://github.com/transitive-bullshit/awesome-puppeteer)

@@ -333,7 +333,7 @@ See [Contributing](https://github.com/puppeteer/puppeteer/blob/main/CONTRIBUTING
Official Firefox support is currently experimental. The ongoing collaboration with Mozilla aims to support common end-to-end testing use cases, for which developers expect cross-browser coverage. The Puppeteer team needs input from users to stabilize Firefox support and to bring missing APIs to our attention.
From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox.
From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox.
We will continue to collaborate with other browser vendors to bring Puppeteer support to browsers such as Safari.
This effort includes exploration of a standard for executing cross-browser commands (instead of relying on the non-standard DevTools Protocol used by Chrome).
@@ -433,7 +433,7 @@ await page.evaluate(() => {
You may find that Puppeteer does not behave as expected when controlling pages that incorporate audio and video. (For example, [video playback/screenshots is likely to fail](https://github.com/puppeteer/puppeteer/issues/291).) There are two reasons for this:
- Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v9.0.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.)
- Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v9.1.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.)
- Since Puppeteer (in all configurations) controls a desktop version of Chromium/Chrome, features that are only supported by the mobile version of Chrome are not supported. This means that Puppeteer [does not support HTTP Live Streaming (HLS)](https://caniuse.com/#feat=http-live-streaming).
#### Q: I am having trouble installing / running Puppeteer in my test environment. Where should I look for help?
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Puppeteer API <!-- GEN:version -->v9.0.0<!-- GEN:stop-->
# Puppeteer API <!-- GEN:version -->v9.1.0<!-- GEN:stop-->

<!-- GEN:empty-if-release --><!-- GEN:stop -->

@@ -516,6 +516,7 @@ Clears all registered handlers.
- `slowMo` <[number]> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.
- `transport` <[ConnectionTransport]> **Experimental** Specify a custom transport object for Puppeteer to use.
- `product` <[string]> Possible values are: `chrome`, `firefox`. Defaults to `chrome`.
- `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[Promise]<[boolean]>|[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets.
- returns: <[Promise]<[Browser]>>

This methods attaches Puppeteer to an existing browser instance.
@@ -623,6 +624,7 @@ try {
- `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
- `pipe` <[boolean]> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`.
- `extraPrefsFirefox` <[Object]> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`)
- `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[Promise]<[boolean]>|[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets.
- returns: <[Promise]<[Browser]>> Promise which resolves to browser instance.

You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppeteer",
"version": "9.0.0",
"version": "9.1.0",
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
"main": "./cjs-entry.js",
"types": "lib/types.d.ts",
@@ -28,7 +28,7 @@
"markdownlint-fix": "prettier --write **/README.md docs/api.md docs/troubleshooting.md",
"lint": "npm run eslint && npm run build && npm run doc && npm run commitlint && npm run markdownlint",
"doc": "node utils/doclint/cli.js",
"clean-lib": "rm -rf lib",
"clean-lib": "rimraf lib",
"build": "npm run tsc && npm run generate-d-ts",
"tsc": "npm run clean-lib && tsc --version && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc -b src/tsconfig.cjs.json",
23 changes: 20 additions & 3 deletions src/common/Browser.ts
Original file line number Diff line number Diff line change
@@ -29,6 +29,13 @@ import { Viewport } from './PuppeteerViewport.js';
*/
export type BrowserCloseCallback = () => Promise<void> | void;

/**
* @public
*/
export type TargetFilterCallback = (
target: Protocol.Target.TargetInfo
) => Promise<boolean> | boolean;

const WEB_PERMISSION_TO_PROTOCOL_PERMISSION = new Map<
Permission,
Protocol.Browser.PermissionType
@@ -189,15 +196,17 @@ export class Browser extends EventEmitter {
ignoreHTTPSErrors: boolean,
defaultViewport?: Viewport | null,
process?: ChildProcess,
closeCallback?: BrowserCloseCallback
closeCallback?: BrowserCloseCallback,
targetFilterCallback?: TargetFilterCallback
): Promise<Browser> {
const browser = new Browser(
connection,
contextIds,
ignoreHTTPSErrors,
defaultViewport,
process,
closeCallback
closeCallback,
targetFilterCallback
);
await connection.send('Target.setDiscoverTargets', { discover: true });
return browser;
@@ -207,6 +216,7 @@ export class Browser extends EventEmitter {
private _process?: ChildProcess;
private _connection: Connection;
private _closeCallback: BrowserCloseCallback;
private _targetFilterCallback: TargetFilterCallback;
private _defaultContext: BrowserContext;
private _contexts: Map<string, BrowserContext>;
/**
@@ -224,14 +234,16 @@ export class Browser extends EventEmitter {
ignoreHTTPSErrors: boolean,
defaultViewport?: Viewport | null,
process?: ChildProcess,
closeCallback?: BrowserCloseCallback
closeCallback?: BrowserCloseCallback,
targetFilterCallback?: TargetFilterCallback
) {
super();
this._ignoreHTTPSErrors = ignoreHTTPSErrors;
this._defaultViewport = defaultViewport;
this._process = process;
this._connection = connection;
this._closeCallback = closeCallback || function (): void {};
this._targetFilterCallback = targetFilterCallback || ((): boolean => true);

this._defaultContext = new BrowserContext(this._connection, this, null);
this._contexts = new Map();
@@ -330,6 +342,11 @@ export class Browser extends EventEmitter {
? this._contexts.get(browserContextId)
: this._defaultContext;

const shouldAttachToTarget = await this._targetFilterCallback(targetInfo);
if (!shouldAttachToTarget) {
return;
}

const target = new Target(
targetInfo,
context,
10 changes: 8 additions & 2 deletions src/common/BrowserConnector.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
*/

import { ConnectionTransport } from './ConnectionTransport.js';
import { Browser } from './Browser.js';
import { Browser, TargetFilterCallback } from './Browser.js';
import { assert } from './assert.js';
import { debugError } from '../common/helper.js';
import { Connection } from './Connection.js';
@@ -43,6 +43,10 @@ export interface BrowserConnectOptions {
* aid debugging.
*/
slowMo?: number;
/**
* Callback to decide if Puppeteer should connect to a given target or not.
*/
targetFilter?: TargetFilterCallback;
}

const getWebSocketTransportClass = async () => {
@@ -71,6 +75,7 @@ export const connectToBrowser = async (
defaultViewport = { width: 800, height: 600 },
transport,
slowMo = 0,
targetFilter,
} = options;

assert(
@@ -106,7 +111,8 @@ export const connectToBrowser = async (
ignoreHTTPSErrors,
defaultViewport,
null,
() => connection.send('Browser.close').catch(debugError)
() => connection.send('Browser.close').catch(debugError),
targetFilter
);
};

3 changes: 2 additions & 1 deletion test/click.spec.ts
Original file line number Diff line number Diff line change
@@ -239,7 +239,8 @@ describe('Page.click', function () {
)
).toBe('clicked');
});
it('should double click the button', async () => {
// See https://github.com/puppeteer/puppeteer/issues/7175
itFailsFirefox('should double click the button', async () => {
const { page, server } = getTestState();

await page.goto(server.PREFIX + '/input/button.html');
33 changes: 31 additions & 2 deletions test/launcher.spec.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import os from 'os';
import path from 'path';
import sinon from 'sinon';
import { promisify } from 'util';
import Protocol from 'devtools-protocol';
import {
getTestState,
itFailsFirefox,
@@ -538,6 +539,35 @@ describe('Launcher specs', function () {
await page.close();
await browser.close();
});
it('should support targetFilter option', async () => {
const { server, puppeteer, defaultBrowserOptions } = getTestState();

const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const browserWSEndpoint = originalBrowser.wsEndpoint();

const page1 = await originalBrowser.newPage();
await page1.goto(server.EMPTY_PAGE);

const page2 = await originalBrowser.newPage();
await page2.goto(server.EMPTY_PAGE + '?should-be-ignored');

const browser = await puppeteer.connect({
browserWSEndpoint,
targetFilter: (targetInfo: Protocol.Target.TargetInfo) =>
!targetInfo.url.includes('should-be-ignored'),
});

const pages = await browser.pages();

await page2.close();
await page1.close();
await browser.close();

expect(pages.map((p: Page) => p.url()).sort()).toEqual([
'about:blank',
server.EMPTY_PAGE,
]);
});
itFailsFirefox(
'should be able to reconnect to a disconnected browser',
async () => {
@@ -587,8 +617,7 @@ describe('Launcher specs', function () {
await browserOne.close();
}
);
// @see https://github.com/puppeteer/puppeteer/issues/6527
itFailsFirefox('should be able to reconnect', async () => {
it('should be able to reconnect', async () => {
const { puppeteer, server } = getTestState();
const browserOne = await puppeteer.launch();
const browserWSEndpoint = browserOne.wsEndpoint();