Skip to content

capture_screenshot region:"chart" captures the first pane, not the active one #4

Description

@stanzhang

On a multi-pane layout, capture_screenshot with region: "chart" returns the first pane in the DOM, not the active one.

src/core/capture.js:

var el = document.querySelector('[data-name="pane-canvas"]')
  || document.querySelector('[class*="chart-container"]')
  || document.querySelector('canvas');

querySelector takes the first match, so on a 2x2 layout every region: "chart" capture is pane 0 regardless of pane_focus.

Reproduce

  1. 4-pane layout, focus pane 3 (pane_focus), give it a different symbol or timeframe from pane 0.
  2. capture_screenshot with region: "chart".

You get pane 0. It bit hardest with replay running on the active pane: the capture showed a live pane while the analysis was of a 2017 bar, and both looked entirely reasonable.

Suggested fix

TradingView marks the focused pane with an active class. This selector picks the right one on 3.3.0:

document.querySelector('.chart-container.active') || document.querySelector('.chart-container')

Reading getBoundingClientRect() off that element and passing it as the CDP clip gives a correctly cropped active pane; verified locally against a single-pane and a 4-pane layout.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions