From 6b40d75d0394ad005379babce9681605d28eba37 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 16 Feb 2021 10:22:46 -0800 Subject: [PATCH] fix: allow setting input files for detached elements (#5467) Fixes #5403 --- src/server/dom.ts | 2 -- test/page-set-input-files.spec.ts | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/server/dom.ts b/src/server/dom.ts index 5197b22a2e..16face0140 100644 --- a/src/server/dom.ts +++ b/src/server/dom.ts @@ -529,8 +529,6 @@ export class ElementHandle extends js.JSHandle { const multiple = throwFatalDOMError(await this._evaluateInUtility(([injected, node]): 'error:notinput' | 'error:notconnected' | boolean => { if (node.nodeType !== Node.ELEMENT_NODE || (node as Node as Element).tagName !== 'INPUT') return 'error:notinput'; - if (!node.isConnected) - return 'error:notconnected'; const input = node as Node as HTMLInputElement; return input.multiple; }, {})); diff --git a/test/page-set-input-files.spec.ts b/test/page-set-input-files.spec.ts index cf69149b62..3e7640489d 100644 --- a/test/page-set-input-files.spec.ts +++ b/test/page-set-input-files.spec.ts @@ -104,15 +104,20 @@ it('should work when file input is attached to DOM', async ({page, server}) => { }); it('should work when file input is not attached to DOM', async ({page, server}) => { - const [chooser] = await Promise.all([ - page.waitForEvent('filechooser'), - page.evaluate(() => { + const [,content] = await Promise.all([ + page.waitForEvent('filechooser').then(chooser => chooser.setFiles(FILE_TO_UPLOAD)), + page.evaluate(async () => { const el = document.createElement('input'); el.type = 'file'; el.click(); + await new Promise(x => el.oninput = x); + const reader = new FileReader(); + const promise = new Promise(fulfill => reader.onload = fulfill); + reader.readAsText(el.files[0]); + return promise.then(() => reader.result); }), ]); - expect(chooser).toBeTruthy(); + expect(content).toBe('contents of the file'); }); it('should not throw when filechooser belongs to iframe', (test, { browserName }) => {