Issue 1:
Context:

Playwright Version: [1.10.0]

Operating System: [Linux]

Node.js version: [14.10.0]

Browser: [Chromium]

Extra: []

Code Snippet

Generate a 400M large file

dd if=/dev/zero of=/tmp/400M bs=1M count=400

const { chromium } = require("playwright");

const dataPath='/tmp/400M';

(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setContent(
'<input type="file" name="fileToUpload" id="fileToUpload">'
);
await page.setInputFiles("input", dataPath);

await browser.close();
})();

Describe the bug

Can't upload a large file(about 400MB).

pw:api => browserType.launch started +0ms
pw:api <= browserType.launch succeeded +85ms
pw:api => browser.newContext started +0ms
pw:api <= browser.newContext succeeded +3ms
pw:api => browserContext.newPage started +0ms
pw:api <= browserContext.newPage succeeded +20ms
pw:api => page.setContent started +1ms
pw:api setting frame content, waiting until "load" +1ms
pw:api navigated to "about:blank" +4ms
pw:api <= page.setContent succeeded +13ms
pw:api => page.setInputFiles started +0ms
pw:api <= page.setInputFiles failed +1s
(node:25801) UnhandledPromiseRejectionWarning: Error: page.setInputFiles: Cannot create a string longer than 0x1fffffe8 characters
at Object.slice (buffer.js:653:37)
at Buffer.toString (buffer.js:801:14)
at /home/king/Desktop/wifi/node_modules/playwright/lib/client/elementHandle.js:280:77
at async Promise.all (index 0)
at async Object.convertInputFiles (/home/king/Desktop/wifi/node_modules/playwright/lib/client/elementHandle.js:275:26)
at async /home/king/Desktop/wifi/node_modules/playwright/lib/client/frame.js:366:60
at async Frame._wrapApiCall (/home/king/Desktop/wifi/node_modules/playwright/lib/client/channelOwner.js:77:28)
at async /home/king/Desktop/wifi/index2.js:12:3
(Use `node --trace-warnings ...` to show where the warning was created)
(node:25801) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:25801) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue 2:
Context:

Playwright Version: 1.3.0

Operating System: Windows

Node.js version: 12.18.3

Browser: Chromium

Code Snippet

const { chromium } = require("playwright");

(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setContent(
'<input type="file" name="fileToUpload" id="fileToUpload">'
);
await page.setInputFiles("input", "path/to/large/file.txt");
await browser.close();
})();

Describe the bug

When uploading large file, about 100MB, page.setInputFiles fails. With Firefox and Webkit it takes some time but it works.

Log:

pw:api => page.setContent started +0ms
pw:api setting frame content, waiting until "load" [] +1ms
pw:api <= page.setContent succeeded +79ms
pw:api => page.setInputFiles started +2ms
pw:api waiting for selector "input" [] +1ms
pw:api selector resolved to visible <input type="file" id="fileToUpload" name="fileToUpload"/> [] +26ms
pw:api <= page.setInputFiles failed +1s
(node:19668) UnhandledPromiseRejectionWarning: page.setInputFiles: Protocol error (Runtime.callFunctionOn): Target closed.
=========================== logs ===========================
[api] waiting for selector "input"
[api] selector resolved to visible <input type="file" id="fileToUpload" name="fileToUpload"/>
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
at C:\dev\playwright\node_modules\playwright\lib\chromium\crConnection.js:131:63
at new Promise (<anonymous>)
at CRSession.send (C:\dev\playwright\node_modules\playwright\lib\chromium\crConnection.js:130:16)
at CRSession.send (C:\dev\playwright\node_modules\playwright\lib\helper.js:80:31)
at CRExecutionContext.evaluateWithArguments (C:\dev\playwright\node_modules\playwright\lib\chromium\crExecutionContext.js:40:79)
at evaluateExpression (C:\dev\playwright\node_modules\playwright\lib\javascript.js:164:40)
at async FrameManager.waitForSignalsCreatedBy (C:\dev\playwright\node_modules\playwright\lib\frames.js:90:24)
at async FrameExecutionContext.evaluateInternal (C:\dev\playwright\node_modules\playwright\lib\dom.js:36:16)
at async CRPage.setInputFiles (C:\dev\playwright\node_modules\playwright\lib\chromium\crPage.js:210:9)
at async C:\dev\playwright\node_modules\playwright\lib\dom.js:440:13
-- ASYNC --
at CRSession.send (C:\dev\playwright\node_modules\playwright\lib\helper.js:79:23)
at CRExecutionContext.evaluateWithArguments (C:\dev\playwright\node_modules\playwright\lib\chromium\crExecutionContext.js:40:79)
at evaluateExpression (C:\dev\playwright\node_modules\playwright\lib\javascript.js:164:40)
at async FrameManager.waitForSignalsCreatedBy (C:\dev\playwright\node_modules\playwright\lib\frames.js:90:24)
at async FrameExecutionContext.evaluateInternal (C:\dev\playwright\node_modules\playwright\lib\dom.js:36:16)
at async CRPage.setInputFiles (C:\dev\playwright\node_modules\playwright\lib\chromium\crPage.js:210:9)
at async C:\dev\playwright\node_modules\playwright\lib\dom.js:440:13
at async FrameManager.waitForSignalsCreatedBy (C:\dev\playwright\node_modules\playwright\lib\frames.js:90:24)
at async ElementHandle._setInputFiles (C:\dev\playwright\node_modules\playwright\lib\dom.js:438:9)
at async C:\dev\playwright\node_modules\playwright\lib\frames.js:674:32
-- ASYNC --
at Frame.setInputFiles (C:\dev\playwright\node_modules\playwright\lib\helper.js:79:23)
at C:\dev\playwright\node_modules\playwright\lib\page.js:407:61
at Page._attributeToPage (C:\dev\playwright\node_modules\playwright\lib\page.js:370:20)
at Page.setInputFiles (C:\dev\playwright\node_modules\playwright\lib\page.js:407:21)
at Page.setInputFiles (C:\dev\playwright\node_modules\playwright\lib\helper.js:80:31)
at C:\dev\playwright\upload.js:9:14
(node:19668) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:19668) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.