Gjs console usage and how to discover interfaces

As an interpreted language JS is great for discovering interfaces as you need them but the gjs-console I have been using is not very featureful. For example it will only print out primitive types and Array objects. If you give it either a plain object or an import object it just prints the type eg [object object] or [object GIRepositoryNamespace] Browser consoles will print out a stringified representation (or even an interactive version) so you can see the properties and methods available.

There is also no tab completion either.

Is there currently some other easy way to inspect objects in gjs? Either in the shell or even just to print in a script too. I tried a for loop which doesn’t look like it works.

As far as I know, there is no way to do what you’re asking. I assume you’re asking about objects which are in fact GObjects under the hood and not regular JavaScript objects/classes. I believe this is because members are exposed on-demand, but I may be wrong about that.

Most of the standard API should be available at https://gjs-docs.gnome.org. If the GObjects in question are either not (such as a number of the subclassed widgets in gnome-shell), you may have to dig into some C code.

There’s a fair amount of work to be done to improve the developer experience (DX) of GJS, for sure:

  • DX Issues that need help in GJS
  • GUADEC Video of the GJS maintainer pleading for help (pleading starts at 7:25)

It’s certainly less convenient to have to ask and wait for an answer, but you’re always welcome to ask about specific interfaces here or on gimpNet/matrix.org:

Yes that sounds familiar from other threads I have read about how it works. I hope things get more like pygobject which provides tons of information about he GObjects interactively. It’s great that this is a project he is asking for help with.

Oh wow those devdocs are awesome too. That helps a ton.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.