Skip to content

Commit

Permalink
core(session): ignore protocol timeouts from puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Oct 3, 2023
1 parent 896399b commit 698dbcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion core/gather/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class ProtocolSession extends CrdpEventEmitter {
}));
});

const resultPromise = this._cdpSession.send(method, ...params);
const resultPromise = this._cdpSession.send(method, ...params).catch(err => {
// We set up our own protocol timeout system, so we should ignore protocol timeouts emitted by puppeteer.
// https://github.com/GoogleChrome/lighthouse/issues/15510
if (/'protocolTimeout'/.test(err)) return;

throw err;
});
const resultWithTimeoutPromise = Promise.race([resultPromise, timeoutPromise]);

return resultWithTimeoutPromise.finally(() => {
Expand Down
19 changes: 18 additions & 1 deletion core/test/gather/session-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ describe('ProtocolSession', () => {
let puppeteerSession;
/** @type {ProtocolSession} */
let session;
let rawSend = fnAny();

beforeEach(() => {
rawSend = fnAny().mockResolvedValue(Promise.resolve());

// @ts-expect-error - Individual mock functions are applied as necessary.
puppeteerSession = new CDPSessionImpl({_rawSend: fnAny(), send: fnAny()}, '', 'root');
puppeteerSession = new CDPSessionImpl({_rawSend: rawSend}, '', 'root');
session = new ProtocolSession(puppeteerSession);
});

Expand Down Expand Up @@ -162,6 +165,20 @@ describe('ProtocolSession', () => {
expect(resultPromise).toBeDone();
expect(await resultPromise).toBe('result');
});

it('should ignore puppeteer protocol timeouts', async () => {
session.setNextProtocolTimeout(Infinity);
expect(session.hasNextProtocolTimeout()).toBe(true);
expect(session.getNextProtocolTimeout()).toBe(Infinity);

// https://github.com/puppeteer/puppeteer/blob/28c1c2662a656a99c049218de4e7ab505c30f04f/packages/puppeteer-core/src/cdp/Connection.ts#L75
rawSend.mockRejectedValue(new Error(`Increase the 'protocolTimeout' setting`));

await session.sendCommand('Page.navigate', {url: ''});

expect(session.hasNextProtocolTimeout()).toBe(false);
expect(session.getNextProtocolTimeout()).toBe(DEFAULT_TIMEOUT);
});
});

describe('.has/get/setNextProtocolTimeout', () => {
Expand Down

0 comments on commit 698dbcd

Please sign in to comment.