Is it possible to make a CLI for your browser extention?

I am thinking about suggesting a feature to a browser extension about adding a CLI to improve things like workflows and all of that, I would also like to develop a browser extension at some point and I use nix/nixos and I would need some way to easily interact with my extension, among other things, I heard nativeMessaging could be a way to interact with it, but it feels a bit janky. How would I go about implementing a CLI for a browser extension? What about the inbuilt browser terminal? It should be possible there.

Hey @spider_under_your_bed. Welcome to the Add-ons Discourse server :slight_smile:

I’m not quite sure I follow what you mean by “inbuilt browser terminal.” If you’re referring to the console/REPL exposed in the developer tools or the browser console, be aware that neither of these UIs provide access to your system shell. While you can design your extensions such that you can invoke commands from a website’s devtools console, you can’t access the extension from the default evaluation context in the browser console.

If you want to integrate an extension directly with your system’s terminal, native messaging is the most direct solution.

When getting started with native messaging, it’s important to understand the role of a native messaging host. This is an application that Firefox start in order to exchange messages with your target application. While the native messaging host can be your main application, in many cases it makes more sense to split it out as another small native app that relays messages between your main app and the browser.

Feel free to ask more questions here as you dig into native messaging for this project!