Getting screenshots and title/application name of a window in ubuntu 22.04 wayland

There is a Linux application that collects activities in the current GUI session: once every time it takes a screenshot of the screen and writes down the name (title) of the window that is in focus and the name of the application that launched this window. The application works as if the session is running in x11. Now we need to add support for the application to run in the wayland environment on Ubuntu 22.04.

I tried to take screenshots in the wayland environment via the gnome dbus API (1), but every The “Share this screenshot with the requesting application” window pops up once. What I tried to fix: use the Screenshot method from here, but on ubuntu 22.04 this only works in unsafe mode

I tried to get the title/name of the application through the gnome dbus API Eval method, but on ubuntu 22.04 this only works in unsafe mode. What I tried to fix: here there is an example of getting the title/name of an application without using Eval, but this also only works in unsafe mode. I also found where examples with code determine the title/name of the application correctly, but not for all windows.

In general, the application should be able to do 2 things on ubuntu 22.04 wayland:

  • Take screenshots without screen flickering or pop-up messages.
  • Receive the title and application name of the window that is in focus, without going into unsafe mode

Can this be achieved?

As I see it, the main problem is that everything works in unsafe mode, but does not work without it.
I read here gnome - Get frontmost window in ubuntu 22.04 with wayland? - Ask Ubuntu that these problems can be solved by creating your own gnome shell extension and in this extension receiving the title/app name and passing it from the extension to my application. This is true?