How to test / debug GNOME Shell extensions? Is there any tool for that?
Asked Answered
O

8

82

I would like to develop GNOME Shell extensions and found it's really easy to step into the development process but I still can't figure out how to debug / test my extensions effectively.

Are there any tools for that purpose? Is there any kind of real time console like we have on modern browsers or javascript servers environments?

Other answered 8/12, 2011 at 3:5 Comment(0)
T
88

Yes, the real-time console is called "Looking Glass" and can be started by pressing Alt+F2 and typing lg at the prompt.

More info: https://live.gnome.org/GnomeShell/LookingGlass

Tragic answered 8/12, 2011 at 9:9 Comment(9)
Just a small doubt about the lookingGlass: I included global.log('hello world'); inside a loop in my extension but nothing got logged in the console. Can't the extensions log messages programatically?Other
I've already got the answer. It logs properly but you have to reload the gnome shell environment after any update in the scripts (<kbd>Alt</kbd>+<kbd>F2</kbd> and type r).Other
Do you know why lg is not working from command-line??!!! working with alt+f2 but not from terminal!Saval
It's not an executable that you can invoke from the command line. It's specific to GNOME shell.Tragic
I'm having the same problem as @marcio, extension log messages don't show up in lg, but I've already restarted the shell. How can I print a message in a gnome shell extension and then see it??Elana
Why not open a new question for that? Few people will see it here.Tragic
@Elana and @marcio: I had the same problem. Just open a terminal and type journalctl -f. After this you will see every log (like global.log('Test');)), errors and so on in the terminal.Chenay
How do you see source code line numbers for the errors?Irradiate
@Irradiate You'd want to trigger an error traceback, for that — something like, globalThis.logError(new Error("Oh no!")); would be logged with a traceback pointing to the location of the error. (Note, though, that when logging real tracebacks — not manually-created ones — that arise from parsing errors, gjs will often attribute the error to the last line of the source file it occurs in, no matter where in the file it's actually located.)Arkhangelsk
I
51

On Fedora 20 (and probably any new linux distro) you can use that command:

journalctl /usr/bin/gnome-session -f -o cat

It constantly (-f) prints errors generated by gnome-session in terminal window. I prefer -o cat flag as it shows full messages without timestaps.

On Fedora 22, I believe, it was replaced with:

journalctl /usr/bin/gnome-shell -f -o cat
Icing answered 31/7, 2014 at 21:8 Comment(5)
This is much better than gnome-shell --replace since id doesn't attaches a gnome shell session to a terminal :)Other
On ubuntu wokrs tooNissensohn
not working on fedora 34/wayland. need to restart session.Effulgence
/usr/bin/gnome-session not found on Linux Mint 20.3 CinnamonSchlep
@Schlep Because Cinnamon is a fork of GNOME Shell; their session manager is called cinnamon-session.Arkhangelsk
C
20

Looking Glass is great. If you need a straight console, though, you can get one, but not through LG, at least not as of 3.6.

If you pop open a terminal and type gnome-shell --replace, gnome-shell will run from there, replacing the running instance, and global log output will thereafter appear in that console.

You can test it with Looking Glass by doing Alt-F2 lg, and thenglobal.log("foo") in the "Evaluator" tab.

Update 11/27/2023

Don't do any of these things if you're running on Wayland; this answer only applies to X11 sessions.

Clingstone answered 26/2, 2013 at 16:11 Comment(5)
When I cancelled gnome-shell after using the approach, everything froze except for my mouse. I had to hard restart my machine to get it working again.Pluvious
That's because you killed your only instance of gnome-shell. Instead of killing it with C-c when you're done, hit C-z to suspend it. Then type bg<CR> into the console (you may not see what you are typing when typing this command) and then gnome-shell will run in the background. Next, run disown <Tab><CR> to detach the process from the terminal window, after which you can safely close the terminal window.Outsail
This is dangerous command, I tried and my gnome-shell was restart from zero and now I cant load any of my extensions.Chance
@Chance It's not a thing you want to run in a Wayland world. There you need to restart the session, no way around it. (This answer predates Wayland.)Arkhangelsk
@Arkhangelsk thanks for the note -- you're right of course! I've added a disclaimer.Clingstone
R
8

I prefer reading ~/.xsession-errors and ~/.cache/gdm/session.log files for more detail. Some of the error messages might have a relation with other exceptions or errors.

Rookie answered 28/12, 2013 at 22:22 Comment(1)
@User231371 would like to point out: In Ubuntu gnome, log are in ~/.cache/upstart/gnome-session.log .Catarrhine
W
7

The other answers didn't really work for me while developing my own extension. What did however was:

journalctl /usr/lib/gnome-session/gnome-session-binary -f -o cat 

If you want to declutter the output to just see your app, you can use:

journalctl /usr/lib/gnome-session/gnome-session-binary -f -o cat | grep [myAppId]

If you also want to access non error logs using the above method above you can use:

global.log('[myAppId]', valueToLog);

If you don't know the correct path to your gnome session you can also use:

journalctl -f | grep gnome-session

Why it was not working is probably because of my gnome-session-binary path was different, which might be related to a newer version of gnome being installed.

Worship answered 27/4, 2017 at 10:2 Comment(3)
On Fedora 26, the correct path is /etc/libexec/gnome-session-binary.Yardstick
However, global.log() messages don't turn up in journalctl output, nor in Looking Glass. Is logging perhaps off by default on Fedora 26?Yardstick
Instead, log messages do show up in journalctl /usr/bin/gnome-shell.Yardstick
S
4

I can't comment on other answers yet, so thought I'd add - however late it may be:

  • For comment 2 of Geoff's answer, just restart the shell via alt+f2 - then r and enter, when that happens - the terminal-run session will end automatically (at least on Debian).

  • I'd recommend jsnjack's answer for general debugging, which works with Debian Jessy as well; probably want to sudo that though. It'll show gnome errors, as well as global.log() messages in whichever terminal you run it in.

If anything, this provides a more complete reference for me - as I've come across this page more than once when referencing info I don't keep fresh in my memory.

Specific answered 20/10, 2014 at 1:45 Comment(0)
D
3

Anjuta Dev-Studio is a great tool for working with gnome-shell extensions; it comes equipped with a debugger, GUI designer, version control, and more. There's even a guided tutorial for using Anjuta with gnome-shell extension projects over on gnome's wiki-pages

Darbies answered 26/1, 2014 at 21:26 Comment(2)
How does the debugger work? Anjuta doesn't even run the extension in any intuitive fashion, it only prints errors. And the wiki link says nothing about Anjuta except that it exists and to recommend not using it!Irradiate
Not sure if the page had changed. You can check other relevant pages for working with the debugger in anjuta; e.g. developer.gnome.org/anjuta-manual/stable/debug-tips.html.enDarbies
P
3

We are developing a emacs package aimed at gnome-shell extension development here: https://github.com/paperwm/gnome-shell-mode

It's still in "beta" (dec. 2017), but its already very useful.

Features

  • Autocompletion (muuuch better than what looking glass provides)
  • Eval of line, selection, current function, buffer (optionally pasting the result into the buffer in a comment)
  • Highlight of error when evaling
  • Documentation lookup helper
  • Helper to reload the module you're working on without restarting gnome-shell
Peabody answered 8/12, 2017 at 23:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.