diff --git a/packages/puppeteer-core/src/common/Connection.ts b/packages/puppeteer-core/src/common/Connection.ts index 0a5c366a..77228a61 100644 --- a/packages/puppeteer-core/src/common/Connection.ts +++ b/packages/puppeteer-core/src/common/Connection.ts @@ -299,8 +299,8 @@ export class Connection extends EventEmitter { */ protected async onMessage(message: string): Promise { if (this.#delay) { - await new Promise(f => { - return setTimeout(f, this.#delay); + await new Promise(r => { + return setTimeout(r, this.#delay); }); } debugProtocolReceive(message); diff --git a/packages/puppeteer-core/src/common/NodeWebSocketTransport.ts b/packages/puppeteer-core/src/common/NodeWebSocketTransport.ts index 2a864df6..6be09b00 100644 --- a/packages/puppeteer-core/src/common/NodeWebSocketTransport.ts +++ b/packages/puppeteer-core/src/common/NodeWebSocketTransport.ts @@ -51,9 +51,11 @@ export class NodeWebSocketTransport implements ConnectionTransport { constructor(ws: NodeWebSocket) { this.#ws = ws; this.#ws.addEventListener('message', event => { - if (this.onmessage) { - this.onmessage.call(null, event.data); - } + setImmediate(() => { + if (this.onmessage) { + this.onmessage.call(null, event.data); + } + }); }); this.#ws.addEventListener('close', () => { if (this.onclose) { diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 35eedc20..9d01bec5 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -2651,6 +2651,12 @@ "parameters": ["firefox", "webDriverBiDi"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[locator.spec] Locator Locator.race races multiple locators", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["cdp", "firefox"], + "expectations": ["SKIP"] + }, { "testIdPattern": "[mouse.spec] Mouse should reset properly", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/locator.spec.ts b/test/src/locator.spec.ts index 1cd518e7..30c11308 100644 --- a/test/src/locator.spec.ts +++ b/test/src/locator.spec.ts @@ -224,6 +224,7 @@ describe('Locator', function () { it('should time out', async () => { const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { const {page} = await getTestState(); @@ -247,6 +248,7 @@ describe('Locator', function () { const {page} = await getTestState(); const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { page.setDefaultTimeout(5000); @@ -268,6 +270,7 @@ describe('Locator', function () { const {page} = await getTestState(); const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { page.setDefaultTimeout(5000); @@ -509,6 +512,7 @@ describe('Locator', function () { const {page} = await getTestState(); const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { await page.setViewport({width: 500, height: 500}); @@ -535,6 +539,7 @@ describe('Locator', function () { it('should time out when all locators do not match', async () => { const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { const {page} = await getTestState(); @@ -630,6 +635,7 @@ describe('Locator', function () { it('should resolve as soon as the predicate matches', async () => { const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, + shouldAdvanceTime: true, }); try { const {page} = await getTestState();