microsoft/playwright · error · Error

Invalid location "${params.location}", expected format is <f

Error message

Invalid location "${params.location}", expected format is <file>:<line>, e.g. "example.spec.ts:42"

What it means

Thrown by the browser_resume devtools tool when params.location contains a colon-separated second segment that is not a valid number. The parser does params.location.split(':') and runs Number(lineStr); if that yields NaN the location is rejected with the documented <file>:<line> contract. A bare file with no colon is accepted (file-only location).

Source

Thrown at packages/playwright-core/src/tools/backend/devtools.ts:63

        if (browserContext.debugger.pausedDetails()) {
          browserContext.debugger.off('pausedstatechanged', listener);
          resolve();
        }
      };
      browserContext.debugger.on('pausedstatechanged', listener);
      browserContext.once('close', () => {
        browserContext.debugger.off('pausedstatechanged', listener);
        resolve();
      });
    });

    if (params.location) {
      const [file, lineStr] = params.location.split(':');
      let location;
      if (lineStr) {
        const line = Number(lineStr);
        if (isNaN(line))
          throw new Error(`Invalid location "${params.location}", expected format is <file>:<line>, e.g. "example.spec.ts:42"`);
        location = { file, line };
      } else {
        location = { file: params.location };
      }
      await browserContext.debugger.runTo(location);
    } else if (params.step) {
      await browserContext.debugger.next();
    } else {
      await browserContext.debugger.resume();
    }
    await pausedPromise;
  },
});

const highlight = defineTabTool({
  capability: 'devtools',
  schema: {
    name: 'browser_highlight',

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Pass location as "<file>:<integer-line>", e.g. "example.spec.ts:42".
  2. Strip any column segment before passing: keep only the first colon and a numeric line.
  3. If you only know the file, omit the line entirely so the file-only branch is used.

Example fix

// before
await resume({ location: 'tests/login.spec.ts:14:8' }); // '14:8' -> NaN -> throws

// after
const [f, l] = 'tests/login.spec.ts:14:8'.split(':');
await resume({ location: `${f}:${l}` }); // 'tests/login.spec.ts:14'
Defensive patterns

Strategy: validation

Validate before calling

function parseLocation(raw: string): { file: string; line?: number } | null {
  const idx = raw.indexOf(':');
  if (idx === -1) return { file: raw };
  const file = raw.slice(0, idx);
  const lineStr = raw.slice(idx + 1);
  // reject any extra colon-separated segments by re-checking for ':'
  if (lineStr.includes(':')) return null;
  const line = Number(lineStr);
  if (!Number.isInteger(line) || line < 1) return null;
  return { file, line };
}

const loc = parseLocation(input);
if (!loc) throw new Error('Use <file>:<line>, e.g. "example.spec.ts:42"');

Type guard

function isValidLocation(s: string): boolean {
  return /^(?:[^:]+)(?::\d+)?$/.test(s);
}

Try / catch

try {
  await resume({ location: input });
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Invalid location')) {
    // prompt the user / agent for <file>:<line> and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking browser_resume with location like "foo.spec.ts:abc" or "foo.spec.ts:" where the line part is non-numeric.

Common situations: Agent pasting a stack-trace fragment that includes a column ("file.ts:12:34") — split keeps "12:34" which is NaN; using a symbol or empty line segment.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/885dd488360b8095. Report an issue: GitHub.