"Mirroring" currently focussed window

On an X.org session I can run the following script to create a replica of the currently focussed window:

#!/usr/bin/env bash

xdotool getwindowfocus | xargs -I% gst-launch-1.0 ximagesrc xid=% ! videoconvert ! autovideosink

This does not work on Wayland. Is there any alternative?

I noticed that there is a pipewire tool called pw-loopback but can’t figure out how to make it work. Any clues?