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: work around a race in waitForFileChooser #8905

Merged
merged 1 commit into from Sep 6, 2022
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
29 changes: 16 additions & 13 deletions src/common/Page.ts
Expand Up @@ -763,25 +763,28 @@ export class Page extends EventEmitter {
* await fileChooser.accept(['/tmp/myfile.pdf']);
* ```
*/
async waitForFileChooser(
options: WaitTimeoutOptions = {}
): Promise<FileChooser> {
if (!this.#fileChooserPromises.size) {
await this.#client.send('Page.setInterceptFileChooserDialog', {
enabled: true,
});
}

waitForFileChooser(options: WaitTimeoutOptions = {}): Promise<FileChooser> {
const needsEnable = this.#fileChooserPromises.size === 0;
const {timeout = this.#timeoutSettings.timeout()} = options;
const promise = createDeferredPromise<FileChooser>({
message: `Waiting for \`FileChooser\` failed: ${timeout}ms exceeded`,
timeout,
});
this.#fileChooserPromises.add(promise);
return promise.catch(error => {
this.#fileChooserPromises.delete(promise);
throw error;
});
let enablePromise: Promise<void> | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybeEnablePromise?

if (needsEnable) {
enablePromise = this.#client.send('Page.setInterceptFileChooserDialog', {
enabled: true,
});
}
return Promise.all([promise, enablePromise])
.then(([result]) => {
return result;
})
.catch(error => {
this.#fileChooserPromises.delete(promise);
throw error;
});
}

/**
Expand Down