Skip to content

Custom viewport is ignored in streaming frames #1031

@voronin-ivan

Description

@voronin-ivan

Summary

If I set a custom viewport, I expect it to be taken into account. It was partially fixed in #952, but not fully, frame messages still contain wrong metadata and image.

Steps to reproduce

import { execSync } from "child_process";

execSync("agent-browser set viewport 1000 1000");
execSync("agent-browser open https://example.com");
await new Promise((r) => setTimeout(r, 2000));

const ws = new WebSocket(
  `ws://localhost:${process.env.AGENT_BROWSER_STREAM_PORT}`,
);

ws.onmessage = (e) => {
  const { data, ...rest } = JSON.parse(e.data);

  console.log("ws message", { ...rest });
};

await new Promise((r) => setTimeout(r, 5_000));
execSync("agent-browser reload");

await new Promise((r) => setTimeout(r, 5_000));
execSync("agent-browser close");
  1. Save this code snippet as repro.mjs
  2. Install the latest agent-browser (I've tested with 0.22.3)
  3. Run AGENT_BROWSER_STREAM_PORT=9224 node repro.mjs

Actual output

ws message {
  connected: true,
  screencasting: false,
  type: 'status',
  viewportHeight: 1000,
  viewportWidth: 1000
}
ws message {
  connected: true,
  screencasting: true,
  type: 'status',
  viewportHeight: 1000,
  viewportWidth: 1000
}
ws message {
  metadata: {
    deviceHeight: 577,
    deviceWidth: 1280,
    offsetTop: 0,
    pageScaleFactor: 1,
    scrollOffsetX: 0,
    scrollOffsetY: 0,
    timestamp: 0
  },
  type: 'frame'
}
ws message {
  metadata: {
    deviceHeight: 577,
    deviceWidth: 1280,
    offsetTop: 0,
    pageScaleFactor: 1,
    scrollOffsetX: 0,
    scrollOffsetY: 0,
    timestamp: 0
  },
  type: 'frame'
}
ws message {
  connected: false,
  screencasting: true,
  type: 'status',
  viewportHeight: 1000,
  viewportWidth: 1000
}

Expected output

deviceWidth, deviceHeight and the image (data) respect the custom viewport.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions