openclaw/openclaw · error

inputRef or element is required

Error message

inputRef or element is required

What it means

Thrown by setInputFilesViaPlaywright (extensions/browser/src/browser/pw-tools-core.interactions.content.ts:435) when neither inputRef nor element is provided. The helper has no way to locate the target input.

Source

Thrown at extensions/browser/src/browser/pw-tools-core.interactions.content.ts:435

  opts: NavigationTargetOptions & {
    inputRef?: string;
    element?: string;
    paths: string[];
  },
): Promise<void> {
  const page = await getPageForTargetId(opts);
  ensurePageState(page);
  restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
  if (!opts.paths.length) {
    throw new Error("paths are required");
  }
  const inputRef = normalizeOptionalString(opts.inputRef) ?? "";
  const element = normalizeOptionalString(opts.element) ?? "";
  if (inputRef && element) {
    throw new Error("inputRef and element are mutually exclusive");
  }
  if (!inputRef && !element) {
    throw new Error("inputRef or element is required");
  }

  const locator = inputRef ? refLocator(page, inputRef) : page.locator(element).first();
  const resolvedResult = await resolveStrictExistingUploadPaths({ requestedPaths: opts.paths });
  if (!resolvedResult.ok) {
    throw new Error(resolvedResult.error);
  }
  const resolvedPaths = resolvedResult.paths;

  try {
    await awaitNavigationGuardedInteraction({
      action: async () => {
        await locator.setInputFiles(resolvedPaths);
      },
      cdpUrl: opts.cdpUrl,
      page,
      ...interactionNavigationPolicy(opts),
      targetId: opts.targetId,

View on GitHub (pinned to 01804a7531)

Solutions

  1. Pass either inputRef (preferred) or a CSS element selector.
  2. Capture the input's ref from a snapshot first.
  3. Validate at least one target identifier is present before calling.

Example fix

// before
await setInputFiles({ paths });
// after
await setInputFiles({ inputRef: 'r3', paths });
Defensive patterns

Strategy: validation

Validate before calling

const inputRef = normalizeOptionalString(opts.inputRef) ?? '';
const element = normalizeOptionalString(opts.element) ?? '';
if (!inputRef && !element) {
  throw new Error("setInputFiles: pass inputRef or element to locate the file input");
}
await setInputFilesViaPlaywright(opts);

Type guard

function hasUploadTarget(opts): boolean {
  return Boolean(opts.inputRef) || Boolean(opts.element);
}

Prevention

When it happens

Trigger: Calling setInputFiles with paths only and no target selector of any kind.

Common situations: Agent assumed the focused element would be used; omitted both fields by mistake.

Related errors


AI-assisted analysis of openclaw/openclaw@01804a7531 (2026-08-12). Data as JSON: /api/errors/87e72f4b84ddf81e. Report an issue: GitHub.