The Viewport class has a queue_screen_capture() function. You can get the viewport with get_tree().get_root().
I never used it yet, but according to documentation you have to call queue_screen_capture(), which will start an asynchronous screen capture. Then, several frames later, you get the screenshot with get_screen_capture(): Viewport — Godot Engine (latest) documentation in English
You can poll for that image in _process() I guess. Then if the image is too big, you can resize it with var thumbnail = captured_image.resized(width, height).
I’ve long not solved this problem. Now I did it. Thank you very much.