Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use setImmediate to reduce flakiness when processing events #12264

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/puppeteer-core/src/node/NodeWebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ 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) {
this.onclose.call(null);
}
setImmediate(() => {
if (this.onclose) {
this.onclose.call(null);
}
});
});
// Silently ignore all errors - we don't know what to do with them.
this.#ws.addEventListener('error', () => {});
Expand Down