Skip to content

Page.getLayoutMetrics not implemented, breaking page.screenshot() #52

Description

@pryceup

Description

Page.getLayoutMetrics CDP method is not implemented, returning an error. This breaks Playwright's page.screenshot() which depends on layout metrics to determine the page dimensions for capturing.

Error

```
Page.screenshot: Protocol error (Page.getLayoutMetrics): Unknown Page method: getLayoutMetrics
```

Where It's Missing

In `crates/obscura-cdp/src/domains/page.rs`, the method dispatch does not have a `getLayoutMetrics` handler, so it falls through to the default error case.

What Playwright Expects

Playwright calls `Page.getLayoutMetrics` before taking a screenshot to get:

  • `contentSize` — full page content dimensions
  • `layoutViewport` — visible viewport dimensions
  • `visualViewport` — visual viewport info

Expected response format:
```json
{
"contentSize": { "x": 0, "y": 0, "width": 1280, "height": 2000 },
"layoutViewport": { "pageX": 0, "pageY": 0, "clientWidth": 1280, "clientHeight": 720 },
"visualViewport": { "offsetX": 0, "offsetY": 0, "pageX": 0, "pageY": 0, "clientWidth": 1280, "clientHeight": 720, "scale": 1 }
}
```

Suggested Fix

Add a `getLayoutMetrics` handler that returns reasonable defaults based on the configured viewport size. Since Obscura doesn't have a visual rendering engine, the values can be derived from:

  • The viewport dimensions set via `Emulation.setDeviceMetricsOverride` (default 1280x720)
  • The DOM content height (can be estimated via JS: `document.documentElement.scrollHeight`)

Reproduction

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
browser = p.chromium.connect_over_cdp("ws://127.0.0.1:9222/devtools/browser")
page = browser.new_context().new_page()
page.goto("https://httpbin.org/html", wait_until="load")
buf = page.screenshot() # Throws: Unknown Page method: getLayoutMetrics
```

Environment

  • Obscura version: v0.1.0
  • Playwright version: 1.49.1 (Python)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions