Skip to content

browser_console_messages reports 0-based line numbers #1839

Closed
microsoft/playwright
#43975

Description

Reproduction

lines.html:

<title>L</title>
<p>two</p>
<p>three</p>
<script>
console.warn("on line 5");
</script>

and ext.js, loaded from a page, with console.error("ext line 2") on its line 2.

Observed

[WARNING] on line 5 @ http://localhost:8765/lines.html:4
[ERROR] ext line 2 @ http://localhost:8765/ext.js:1

Expected

lines.html:5 and ext.js:2, the 1-based numbers that editors and DevTools show. Ideally the column too (:5:9).

Cause

ConsoleMessage.location().lineNumber is 0-based (per the Playwright API docs), and tab.ts:662 prints it as is. A model that follows these numbers into a source file looks one line too early.

Version: @playwright/mcp@0.0.84 (playwright-core 1.65.0-alpha-2026-10-30), Linux, Chrome. Source references are microsoft/playwright main @ 58d69dc, packages/playwright-core/src/tools/.

Activity

  1. github-actions commented on Nov 6, 2026

    @github-actions
  2. microsoft-playwright-automation commented on Nov 6, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I reproduced this and prepared a fix.

    Reproduced on Linux in Chrome, Chromium, Firefox and WebKit, at upstream 1.66.0-next (dc668b5a44c1810a06c7114f405c9ecf975f15ec). The shared formatter prints Playwright's zero-based line unchanged. The fix converts it to one-based output for console responses and console log files, keeping the existing URL:line format.

    Reproduction and checks

    The existing browser_console_messages test now loads an HTML page with console.log("Hello, world!") on line 5 and an external /ext.js containing \nconsole.error("Error");, on line 2. Before the fix, all four headless browser projects return:

    [LOG] Hello, world! @ http://localhost:<port>/:4
    [ERROR] Error @ http://localhost:<port>/ext.js:1
    

    The regression asserts /:5 and /ext.js:2. No browser-specific difference was observed.

    After the fix, npm run test-mcp -- console.spec.ts cli-devtools.spec.ts --project=chrome --project=chromium --project=firefox --project=webkit --reporter=line passed all 168 checks. npm run build and npm run flint also passed.

    Draft PR: microsoft/playwright#43975

    Triaged on Linux by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions