grafana/k6 · error
parsing setInputFiles parameter
Error message
parsing setInputFiles parameter: %w
What it means
Thrown when the files argument of ElementHandle.setInputFiles fails Files.Parse. The k6 browser module accepts only file descriptor objects {name, mimeType, buffer} (buffer is a base64 string) or arrays of them — unlike Playwright, plain file paths and strings are rejected with the wrapped error 'invalid parameter type : string', and a malformed object yields 'parsing file descriptor: ...'. This is the most common setInputFiles failure.
Solutions
- Pass a descriptor object: setInputFiles({name: 'avatar.png', mimeType: 'image/png', buffer: '<base64>'})
- For multiple files pass an array of descriptor objects
- To use local file contents, load them as base64 in the script and put the base64 string in buffer — the module does not read paths from disk
Example fix
// before (Playwright style — not supported by k6)
await handle.setInputFiles('/uploads/avatar.png');
// after
await handle.setInputFiles({
name: 'avatar.png',
mimeType: 'image/png',
buffer: 'iVBORw0KGgoAAAANSUhEUg...', // base64 string
}); Defensive patterns
Strategy: type-guard
Validate before calling
function isFileDescriptor(v) {
return typeof v?.name === 'string' && typeof v?.buffer === 'string';
}
const arr = Array.isArray(files) ? files : [files];
if (files != null && !arr.every(isFileDescriptor)) {
throw new Error('setInputFiles requires {name, mimeType, buffer(base64)} objects, not paths');
}
await handle.setInputFiles(files); Type guard
function isFileDescriptor(v) {
return v != null && typeof v === 'object' && !Array.isArray(v) &&
typeof v.name === 'string' && typeof v.mimeType === 'string' &&
typeof v.buffer === 'string';
}
function isInputFilesArg(v) {
return v == null || isFileDescriptor(v) || (Array.isArray(v) && v.every(isFileDescriptor));
} Try / catch
try {
await handle.setInputFiles(files);
} catch (e) {
if (String(e).includes('setInputFiles parameter')) {
// a path string slipped in; convert it to a descriptor before retrying
throw new Error('k6 setInputFiles does not accept file paths; pass {name, mimeType, buffer}');
}
throw e;
} Prevention
- Never port Playwright setInputFiles('/path') calls verbatim — k6 has no path support
- Encode file payloads as base64 strings in the buffer field
- Wrap file arguments in a descriptor factory so every call site is shape-checked once
When it happens
Trigger: setInputFiles('/uploads/avatar.png') (string path — unsupported), setInputFiles(42), setInputFiles([{name: 'a.png'}]) with wrong/missing field types, or an array mixing strings and objects.
Common situations: Copying Playwright test code where setInputFiles('/path/to/file.pdf') is idiomatic; assuming k6 can read local files by path; passing a Buffer/ArrayBuffer instead of a base64 string for the buffer field.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- parsing setInputFiles options
- setting input files
- checking hit target
- getting element position
- getting injected script
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/79a7d4cf5a2e5f91.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:244
}), nil
},
"setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing setChecked options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.SetChecked(checked, popts) //nolint:wrapcheck
}), nil
},
"setInputFiles": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseElementHandleSetInputFilesOptions(rt, opts, eh.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing setInputFiles options: %w", err)
}
var pfiles common.Files
if err := pfiles.Parse(vu.Context(), files); err != nil {
return nil, fmt.Errorf("parsing setInputFiles parameter: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck
}), nil
},
"tap": func(opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseElementHandleTapOptions(rt, opts, eh.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing element tap options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.Tap(popts) //nolint:wrapcheck
}), nil
},
"textContent": func() *sobek.Promise {
return promise(vu, func() (any, error) {
s, ok, err := eh.TextContent()
if err != nil {View on GitHub (pinned to 3fcf5388d7)