Use DBus service "org.freedesktop.portal.Screenshot" when available
Wayland does not specify a native compositor interface for taking screenshots yet (see here).
Currently screenshooter can not take screenshots in a native wayland session (segfault without xwayland).
Though there is a DBUS API to take screenshots in a wayland session offered by xdg-desktop-portal. The service is offered e.g. by mutter (xdg-desktop-portal-gtk) and wlroots (via xdg-desktop-portal-wlr backend).
So the idea would be, to check if that DBus Service is available, and if so, use it, instead of the X11 way to gather screenshots. (Maybe additionally check if the session type is WAYLAND)