Skip to content

Commit

Permalink
fix: allow setting input files for detached <input> elements (#5467)
Browse files Browse the repository at this point in the history
Fixes #5403
  • Loading branch information
aslushnikov authored Feb 16, 2021
1 parent 4f1d84d commit 6b40d75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/server/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {}));
Expand Down
13 changes: 9 additions & 4 deletions test/page-set-input-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 6b40d75

Please sign in to comment.