2

Trivial example: Under Ubuntu 20.04, the following command:

gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval true

produces this output:

(true, 'true')

but under 22.04 the same command produces this output:

(false,'')

The same output is produced for any other "Eval" statement I've tried under 22.04.

What's going wrong? The 20.04 and 22.04 systems are both newly-installed, vanilla installations.

Update: This seems to be one of the problems that gcdev (https://askubuntu.com/users/1216972/gcdev) was trying to report earlier:

How to get the current active window in Ubuntu 22.04?

2 Answers2

4

Like everywhere else, stricter security is also being implemented in Gnome Shell.

The org.gnome.Shell interface provides a private API to other core components to implement desktop functionalities like Settings or global keybindings. It is not meant as a public API, so limit it to a set of expected callers.

(https://gitlab.gnome.org/GNOME/gnome-shell/-/commit/a628bbc4)

This is why many such commands no longer work. One can enter global.context.unsafe_mode = true in the Looking Glass (Alt+F2, lg Enter) to make them work for the current session. There is an extension, Unsafe mode menu, that allows to toggle between safe and unsafe mode (with thanks to Bryan Wright). It should also be possible to start Gnome Shell with an --unsafe option.

vanadium
  • 88,010
  • Thanks. I see that there's also an extension that adds a "safe/unsafe" toggle button to the panel menu: https://github.com/linushdot/unsafe-mode-menu – Bryan Wright Jun 06 '22 at 17:31
  • Very useful information, thanks! I added this to the answer. – vanadium Jun 06 '22 at 20:45
  • Thanks! I can get on board with this, but it's really bad style to not print some sort of error when rejecting these calls... – olejorgenb Nov 24 '23 at 11:41
2

To add to vanadium's answer,

Here is a script that attaches gdb to the gnome-shell process, and invokes the javascript engine to toggle the unsafe variable.

This means that as long as nothing breaks during this process, you don't need to restart the session to add the flag, or deal with addons, or anything like that.

This is the important line:

gdb -p "$gnome_pid" -batch -ex "call (void*)gjs_context_eval((void*)gjs_context_get_current(), "$1", -1, "", 0, 0)"

Replace $1 with the code that needs to be run, like:

global.context.unsafe_mode = true

Note that this is somewhat dangerous and unsupported. The session will hang if gdb doesn't finish. I recommend running it in screen or tmux, and having some way to get access to that if your UI hangs.

tabbie
  • 31