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

Reject events promises when the client is disconnected #565

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nathan818fr
Copy link

@nathan818fr nathan818fr commented Oct 20, 2024

First commit

Fixes an issues where concurrent close calls don't call all the callbacks.

const chrome = await Chrome();
chrome.close(() => console.log('1'));
chrome.close(() => console.log('2'));

Before: Only 2 was printed.
After: Both 1 and 2 are printed.

Side-note: not calling the 'disconnect' event on user-initiated close seems like a strange API design decision.
I kept this behavior here, but I think you should consider changing this in the future (or at least add an event emitted in both cases).

Second commit

Ensures that promises waiting for CDP events are rejected when the client disconnects.
It's like #489, but for the events instead of commands.

const chrome = await Chrome();
const promise = chrome.Page.loadEventFired();
chrome.close();
await promise;

Before: The promise was waiting forever.
After: The promise is rejected with a 'client disconnected' error.

When calling close() multiple times, only the last callback was called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant