From 8eace6a162f2362b6fbe79df7e21f357c79138c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Apr 2022 08:50:01 +0200 Subject: [PATCH 1/6] chore(deps-dev): bump eslint from 8.12.0 to 8.13.0 (#8219) Bumps [eslint](https://github.com/eslint/eslint) from 8.12.0 to 8.13.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.12.0...v8.13.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eaafe57a4af96..ed7ac00a642fa 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "@web/test-runner": "0.13.27", "commonmark": "0.30.0", "cross-env": "7.0.3", - "eslint": "8.12.0", + "eslint": "8.13.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-mocha": "10.0.3", From 8cd3a1e3ca87a40d5e65aed2ff47f056b5162450 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Apr 2022 07:10:26 +0000 Subject: [PATCH 2/6] chore(deps): bump actions/setup-node from 3.1.0 to 3.1.1 (#8229) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v3.1.0...v3.1.1) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3ea8c648db493..190667bbffd6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: fetch-depth: 2 - name: Set up Node.js - uses: actions/setup-node@v3.1.0 + uses: actions/setup-node@v3.1.1 with: node-version: ${{ matrix.node }} @@ -107,7 +107,7 @@ jobs: fetch-depth: 2 - name: Set up Node.js - uses: actions/setup-node@v3.1.0 + uses: actions/setup-node@v3.1.1 with: # Test only the oldest maintenance LTS Node.js version. # https://github.com/nodejs/Release#release-schedule @@ -148,7 +148,7 @@ jobs: fetch-depth: 2 - name: Set up Node.js - uses: actions/setup-node@v3.1.0 + uses: actions/setup-node@v3.1.1 with: # Test only the oldest maintenance LTS Node.js version. # https://github.com/nodejs/Release#release-schedule From 91a8e73b1196e4128b1e7c25e08080f2faaf3cf7 Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Tue, 19 Apr 2022 02:28:44 -0700 Subject: [PATCH 3/6] fix: forget queuedEventGroup when emitting response in responseReceivedExtraInfo (#8234) (#8239) --- src/common/NetworkEventManager.ts | 4 + src/common/NetworkManager.ts | 1 + test/NetworkManager.spec.ts | 117 ++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) diff --git a/src/common/NetworkEventManager.ts b/src/common/NetworkEventManager.ts index aa8e1adc3f84b..704a79dc3ca3f 100644 --- a/src/common/NetworkEventManager.ts +++ b/src/common/NetworkEventManager.ts @@ -184,4 +184,8 @@ export class NetworkEventManager { ): void { this._queuedEventGroupMap.set(networkRequestId, event); } + + forgetQueuedEventGroup(networkRequestId: NetworkRequestId): void { + this._queuedEventGroupMap.delete(networkRequestId); + } } diff --git a/src/common/NetworkManager.ts b/src/common/NetworkManager.ts index a5a440114c035..84efafa3361bb 100644 --- a/src/common/NetworkManager.ts +++ b/src/common/NetworkManager.ts @@ -519,6 +519,7 @@ export class NetworkManager extends EventEmitter { event.requestId ); if (queuedEvents) { + this._networkEventManager.forgetQueuedEventGroup(event.requestId); this._emitResponseEvent(queuedEvents.responseReceivedEvent, event); if (queuedEvents.loadingFinishedEvent) { this._emitLoadingFinished(queuedEvents.loadingFinishedEvent); diff --git a/test/NetworkManager.spec.ts b/test/NetworkManager.spec.ts index de1339754f41b..a065ee5cbc81a 100644 --- a/test/NetworkManager.spec.ts +++ b/test/NetworkManager.spec.ts @@ -543,4 +543,121 @@ describeChromeOnly('NetworkManager', () => { expect(requests.length).toBe(2); }); + it(`should handle Network.responseReceivedExtraInfo event after Network.responseReceived event (github.com/puppeteer/puppeteer/issues/8234)`, async () => { + const mockCDPSession = new MockCDPSession(); + const manager = new NetworkManager(mockCDPSession, true, { + frame(): Frame | null { + return null; + }, + }); + + const requests: HTTPRequest[] = []; + manager.on( + NetworkManagerEmittedEvents.RequestFinished, + (request: HTTPRequest) => { + requests.push(request); + } + ); + + mockCDPSession.emit('Network.requestWillBeSent', { + requestId: '1360.2', + loaderId: '9E86B0282CC98B77FB0ABD49156DDFDD', + documentURL: 'http://this.is.the.start.page.com/', + request: { + url: 'http://this.is.a.test.com:1080/test.js', + method: 'GET', + headers: { + 'Accept-Language': 'en-US,en;q=0.9', + Referer: 'http://this.is.the.start.page.com/', + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.0 Safari/537.36', + }, + mixedContentType: 'none', + initialPriority: 'High', + referrerPolicy: 'strict-origin-when-cross-origin', + isSameSite: false, + }, + timestamp: 10959.020087, + wallTime: 1649712607.861365, + initiator: { + type: 'parser', + url: 'http://this.is.the.start.page.com/', + lineNumber: 9, + columnNumber: 80, + }, + redirectHasExtraInfo: false, + type: 'Script', + frameId: '60E6C35E7E519F28E646056820095498', + hasUserGesture: false, + }); + mockCDPSession.emit('Network.responseReceived', { + requestId: '1360.2', + loaderId: '9E86B0282CC98B77FB0ABD49156DDFDD', + timestamp: 10959.042529, + type: 'Script', + response: { + url: 'http://this.is.a.test.com:1080', + status: 200, + statusText: 'OK', + headers: { + connection: 'keep-alive', + 'content-length': '85862', + }, + mimeType: 'text/plain', + connectionReused: false, + connectionId: 119, + remoteIPAddress: '127.0.0.1', + remotePort: 1080, + fromDiskCache: false, + fromServiceWorker: false, + fromPrefetchCache: false, + encodedDataLength: 66, + timing: { + requestTime: 10959.023904, + proxyStart: -1, + proxyEnd: -1, + dnsStart: 0.328, + dnsEnd: 2.183, + connectStart: 2.183, + connectEnd: 2.798, + sslStart: -1, + sslEnd: -1, + workerStart: -1, + workerReady: -1, + workerFetchStart: -1, + workerRespondWithSettled: -1, + sendStart: 2.982, + sendEnd: 3.757, + pushStart: 0, + pushEnd: 0, + receiveHeadersEnd: 16.373, + }, + responseTime: 1649712607880.971, + protocol: 'http/1.1', + securityState: 'insecure', + }, + hasExtraInfo: true, + frameId: '60E6C35E7E519F28E646056820095498', + }); + mockCDPSession.emit('Network.responseReceivedExtraInfo', { + requestId: '1360.2', + blockedCookies: [], + headers: { + connection: 'keep-alive', + 'content-length': '85862', + }, + resourceIPAddressSpace: 'Private', + statusCode: 200, + headersText: + 'HTTP/1.1 200 OK\r\nconnection: keep-alive\r\ncontent-length: 85862\r\n\r\n', + }); + mockCDPSession.emit('Network.loadingFinished', { + requestId: '1360.2', + timestamp: 10959.060708, + encodedDataLength: 85928, + shouldReportCorbBlocking: false, + }); + + expect(requests.length).toBe(1); + }); }); From 95c9f392e2cc5644419924bce4a4e6484622daf7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Apr 2022 11:34:53 +0000 Subject: [PATCH 4/6] chore(deps): bump github/codeql-action from 2.1.7 to 2.1.8 (#8220) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.7 to 2.1.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/0182a2c78c8a55b763909348834ed54d735ab3e2...1ed1437484560351c5be56cf73a48a279d116b78) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 6165958db15da..c8b20ff70df8d 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -46,6 +46,6 @@ jobs: # Upload the results to GitHub’s code scanning dashboard. - name: 'Upload to code-scanning' - uses: github/codeql-action/upload-sarif@0182a2c78c8a55b763909348834ed54d735ab3e2 # v1.0.26 + uses: github/codeql-action/upload-sarif@1ed1437484560351c5be56cf73a48a279d116b78 # v1.0.26 with: sarif_file: results.sarif From b6504d7186336a2fc0b41c3878c843b7409ba5fb Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Tue, 19 Apr 2022 14:09:23 +0200 Subject: [PATCH 5/6] fix: also kill Firefox when temporary profile is used (#8233) * fix: also kill Firefox when temporary profile is used * fix: use separate tests for Puppeteer.launch should filter out ignored default arguments --- src/node/BrowserRunner.ts | 2 +- test/launcher.spec.ts | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/node/BrowserRunner.ts b/src/node/BrowserRunner.ts index 46d322e9ce11e..f2dc6075857e7 100644 --- a/src/node/BrowserRunner.ts +++ b/src/node/BrowserRunner.ts @@ -164,7 +164,7 @@ export class BrowserRunner { close(): Promise { if (this._closed) return Promise.resolve(); - if (this._isTempUserDataDir && this._product !== 'firefox') { + if (this._isTempUserDataDir) { this.kill(); } else if (this.connection) { // Attempt to close the browser gracefully diff --git a/test/launcher.spec.ts b/test/launcher.spec.ts index 46d56c554dfd1..1e45fea435693 100644 --- a/test/launcher.spec.ts +++ b/test/launcher.spec.ts @@ -404,7 +404,7 @@ describe('Launcher specs', function () { await page.close(); await browser.close(); }); - it('should filter out ignored default arguments', async () => { + itChromeOnly('should filter out ignored default arguments', async () => { const { defaultBrowserOptions, puppeteer } = getTestState(); // Make sure we launch with `--enable-automation` by default. const defaultArgs = puppeteer.defaultArgs(); @@ -423,6 +423,25 @@ describe('Launcher specs', function () { expect(spawnargs.indexOf(defaultArgs[2])).toBe(-1); await browser.close(); }); + itFirefoxOnly('should filter out ignored default arguments', async () => { + const { defaultBrowserOptions, puppeteer } = getTestState(); + + const defaultArgs = puppeteer.defaultArgs(); + const browser = await puppeteer.launch( + Object.assign({}, defaultBrowserOptions, { + // Only the first argument is fixed, others are optional. + ignoreDefaultArgs: [defaultArgs[0]], + }) + ); + const spawnargs = browser.process().spawnargs; + if (!spawnargs) { + throw new Error('spawnargs not present'); + } + expect(spawnargs.indexOf(defaultArgs[0])).toBe(-1); + expect(spawnargs.indexOf(defaultArgs[1])).not.toBe(-1); + await browser.close(); + }); + it('should have default URL when launching browser', async function () { const { defaultBrowserOptions, puppeteer } = getTestState(); const browser = await puppeteer.launch(defaultBrowserOptions); From 0c8174b987ad4a44abbb5a7d281d588bc9346da0 Mon Sep 17 00:00:00 2001 From: Andreas Opferkuch Date: Tue, 19 Apr 2022 14:48:22 +0200 Subject: [PATCH 6/6] docs: improve custom query handler docs (#8235) --- docs/api.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index f1606dd1d3efb..65ec66ee0482c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -721,7 +721,7 @@ The product is set by the `PUPPETEER_PRODUCT` environment variable or the `produ - `name` <[string]> The name that the custom query handler will be registered under. - `queryHandler` <[CustomQueryHandler]> The [custom query handler](#interface-customqueryhandler) to register. -Registers a [custom query handler](#interface-customqueryhandler). After registration, the handler can be used everywhere where a selector is expected by prepending the selection string with `/`. The name is only allowed to consist of lower and upper case Latin letters. +Registers a [custom query handler](#interface-customqueryhandler). Example: @@ -5525,7 +5525,11 @@ This method is identical to `off` and maintained for compatibility with Node's E ### interface: CustomQueryHandler -Contains two functions `queryOne` and `queryAll` that can be [registered](#puppeteerregistercustomqueryhandlername-queryhandler) as alternative querying strategies. The functions `queryOne` and `queryAll` are executed in the page context. `queryOne` should take an `Element` and a selector string as argument and return a single `Element` or `null` if no element is found. `queryAll` takes the same arguments but should instead return a `NodeList` or `Array` with all the elements that match the given query selector. +After [registration](#puppeteerregistercustomqueryhandlername-queryhandler), the handler can be used everywhere where a selector is expected by prepending the selection string with `/`. The name is only allowed to consist of lower and upper case Latin letters. + +Contains two functions `queryOne` and `queryAll` that are executed in the page context. `queryOne` should take an `Element` and a selector string as argument and return a single `Element` or `null` if no element is found. `queryAll` takes the same arguments but should instead return a `NodeList` or `Array` with all the elements that match the given query selector. + +**NOTE:** Because the function code needs to be serialized, it is **not possible** to access anything outside its scope or use imports. See e.g. [the pierce handler](https://github.com/puppeteer/puppeteer/blob/v13.5.2/src/common/QueryHandler.ts#L115) which has redundancies because of this limitation. ### interface: Selector @@ -5534,7 +5538,7 @@ The default behavior is to regard the string as a [CSS selector] and query using If a selector string contains a forward slash `/` the selector is instead regarded as custom selector where everything before the slash is the [custom handler](#puppeteerregistercustomqueryhandlername-queryhandler) name and everything after is the selector: `/`. Puppeteer ships with two such custom handlers pre-registered: -- `aria/`: Queries the accessibilty tree for computed accessibility properties. +- `aria`: Queries the accessibilty tree for computed accessibility properties. The selectors consist of an accessible name to query for and optionally further aria attributes on the form `[=]`. Currently, we only support the `name` and `role` attribute.