mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
b4f5ea1167
commit
053d960fb5
@ -763,22 +763,25 @@ 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 => {
|
||||
let enablePromise: Promise<void> | undefined;
|
||||
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;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user