diff --git a/packages/puppeteer-core/src/bidi/ElementHandle.ts b/packages/puppeteer-core/src/bidi/ElementHandle.ts index 7e42e80011d31..dcf8270e2e963 100644 --- a/packages/puppeteer-core/src/bidi/ElementHandle.ts +++ b/packages/puppeteer-core/src/bidi/ElementHandle.ts @@ -102,13 +102,15 @@ export class BidiElementHandle< ): Promise { // Locate all files and confirm that they exist. const path = environment.value.path; - files = files.map(file => { - if (path.win32.isAbsolute(file) || path.posix.isAbsolute(file)) { - return file; - } else { - return path.resolve(file); - } - }); + if (path) { + files = files.map(file => { + if (path.win32.isAbsolute(file) || path.posix.isAbsolute(file)) { + return file; + } else { + return path.resolve(file); + } + }); + } await this.frame.setFiles(this, files); } diff --git a/packages/puppeteer-core/src/cdp/ElementHandle.ts b/packages/puppeteer-core/src/cdp/ElementHandle.ts index 9f6c0c063b49e..2b5ad462ed0c8 100644 --- a/packages/puppeteer-core/src/cdp/ElementHandle.ts +++ b/packages/puppeteer-core/src/cdp/ElementHandle.ts @@ -101,25 +101,30 @@ export class CdpElementHandle< @bindIsolatedHandle override async uploadFile( this: CdpElementHandle, - ...filePaths: string[] + ...files: string[] ): Promise { const isMultiple = await this.evaluate(element => { return element.multiple; }); assert( - filePaths.length <= 1 || isMultiple, + files.length <= 1 || isMultiple, 'Multiple file uploads only work with ', ); // Locate all files and confirm that they exist. const path = environment.value.path; - const files = filePaths.map(filePath => { - if (path.win32.isAbsolute(filePath) || path.posix.isAbsolute(filePath)) { - return filePath; - } else { - return path.resolve(filePath); - } - }); + if (path) { + files = files.map(filePath => { + if ( + path.win32.isAbsolute(filePath) || + path.posix.isAbsolute(filePath) + ) { + return filePath; + } else { + return path.resolve(filePath); + } + }); + } /** * The zero-length array is a special case, it seems that diff --git a/packages/puppeteer-core/src/environment.ts b/packages/puppeteer-core/src/environment.ts index e31dd1bde3015..00c81aa7d2a6a 100644 --- a/packages/puppeteer-core/src/environment.ts +++ b/packages/puppeteer-core/src/environment.ts @@ -16,7 +16,7 @@ export const isNode = !!(typeof process !== 'undefined' && process.version); export interface EnvironmentDependencies { fs: typeof FS; - path: typeof Path; + path?: typeof Path; ScreenRecorder: typeof ScreenRecorder; } @@ -31,9 +31,6 @@ export const environment: { get fs(): typeof FS { throw new Error('fs is not available in this environment'); }, - get path(): typeof Path { - throw new Error('path is not available in this environment'); - }, get ScreenRecorder(): typeof ScreenRecorder { throw new Error('ScreenRecorder is not available in this environment'); },