Unable to call the remote GetWindows gnome method via dbus

Ubuntu 22.04 wayland GNOME Shell 42.9

I’m trying to call the GetWindows method from the gnome dbus api data/dbus-interfaces/org.gnome.Shell.Introspect.xml · main · GNOME / gnome-shell · GitLab
When I run the code below I get the error:
сalling GetWindows()... ** ERROR:main.c:18:test_getwindows: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: GetWindows is not allowed (g-dbus-error-quark, 9) Bail out! ERROR:main.c:18:test_getwindows: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: GetWindows is not allowed (g-dbus-error-quark, 9)

AccessDenied led me to think that I needed to run the code via sudo, but this gave another error: Calling GetWindows()... ** ERROR:main.c:18:test_getwindows: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Shell was not provided by any .service files (g-dbus-error-quark, 2) Bail out! ERROR:main.c:18:test_getwindows: assertion failed (error == NULL): GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Shell was not provided by any .service files (g-dbus-error-quark, 2) Aborted

#include <stdbool.h>
#include <stdio.h>
#include <glib/gprintf.h>
#include <gio/gio.h>


void test_getwindows(GDBusProxy *proxy)
{
   GError *error = NULL;
   g_printf("Calling GetWindows()...\n");
   g_dbus_proxy_call_sync(proxy,
           "GetWindows",
           NULL,
           G_DBUS_CALL_FLAGS_NONE,
           -1,
           NULL,
           &error);
   g_assert_no_error(error);
}

int main(void)
{
   GDBusProxy *proxy;
   GDBusConnection *conn;
   GError *error = NULL;

   conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
   g_assert_no_error(error);

   proxy = g_dbus_proxy_new_sync(conn,
              G_DBUS_PROXY_FLAGS_NONE,
              NULL,
              "org.gnome.Shell", 
              "/org/gnome/Shell/Introspect",
              "org.gnome.Shell.Introspect",
              NULL,
              &error);
   g_assert_no_error(error);

   test_getwindows(proxy);
   return 0;
}

No, sudo has nothing to do with access control over D-Bus.

The Shell checks for access against an allow-list of D-Bus senders—namely, the XDG desktop portals—or if the shell is in unsafe mode.

You are not allowed to get the list of windows unless you are a privileged component, or you explicitly set the Shell in unsafe mode using Looking Glass.

What is a privileged component? how to become one? Is gnome extension a privileged component?
@ebassi

A system component that is necessary to run the session, like the compositor or the XDG desktop portal implementation.

By being necessary to run the session; you cannot promote any random application, and you definitely cannot do that programmatically, as it would defeat the entire point.

A Shell extension runs inside the compositor, so it is by definition privileged; but it’s also moot, as a shell extension would not use the D-Bus API in the first place, since it has access to the same information as the rest of the compositor.

how to take a screenshot from inside the gnome extension, if not through the dbus API?
@ebassi

By using the functions from the Shell: js/ui/screenshot.js · main · GNOME / gnome-shell · GitLab

GNOME Shell does not call D-Bus internally: the D-Bus interface is for external consumers.

If this is a public API, is it documented somewhere?
@ebassi

I think you’re having some issues with regards to what Shell extensions are, and how they work. I recommend reading the extensions guide.

Perhaps Shell.Screenshot is what you’re looking for.

As I understand it, this is C api, not javascript. And I need to take a screenshot from a gnome extension written in javascript. Or did I understand something wrong?
@jadahl

You can call C API from JavaScript: that’s how GNOME Shell is implemented.

Once again, I strongly urge you to learn how extensions work before asking questions that can easily be answered by reading the documentation.

I read the Architecture and Anatomy topics from the link you posted above, but it didn’t answer my questions

Maybe you could tell me what additional topics need to be studied in order to understand how to take a screenshot from the gnome extension, for example
@ebassi