fix: allow setting input files for detached <input> elements (#5467)

Fixes #5403
This commit is contained in:
Andrey Lushnikov 2021-02-16 10:22:46 -08:00 committed by GitHub
parent 4f1d84d6b9
commit 6b40d75d03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -529,8 +529,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
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;
}, {}));

View file

@ -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 }) => {