Screen capture outside of a viewport

:bust_in_silhouette: Reply From: Zylann

No, screen capture only works on stuff that Godot has rendered. If it’s not rendered due to being off screen, you can’t capture it.
At least, not with the default viewport.

One way you could achieve this however, is to have a second SubViewport ( SubViewport — Godot Engine (stable) documentation in English) that does not render on the screen. That viewport would have to share the same world (2D or 3D?) by assigning its world_2d or world_3d property with a script, and have a Camera2D or Camera3D child node defining from where it renders things.
It’s a similar setup as if you were doing a split-screen game, except the second view is not rendered on screen.
Once you have that viewport, you can position its camera where you want and then grab a screenshot from it after at least one frame has passed.
Also if you only need a still image, you may want to turn off that viewport once it’s done capturing so the game doesn’t keep rendering unnecessary stuff.