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
- 4-pane layout, focus pane 3 (
pane_focus), give it a different symbol or timeframe from pane 0.
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.
On a multi-pane layout,
capture_screenshotwithregion: "chart"returns the first pane in the DOM, not the active one.src/core/capture.js:querySelectortakes the first match, so on a 2x2 layout everyregion: "chart"capture is pane 0 regardless ofpane_focus.Reproduce
pane_focus), give it a different symbol or timeframe from pane 0.capture_screenshotwithregion: "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
activeclass. This selector picks the right one on 3.3.0:Reading
getBoundingClientRect()off that element and passing it as the CDPclipgives a correctly cropped active pane; verified locally against a single-pane and a 4-pane layout.