Search code examples
firefoxfirefox-addonxpcom

Can an standalone / external C++ executable or JavaScript create cookies for Firefox?


I need to create/update/remove cookie for FireFox browser. This cookie is a client cookie, as in it has to be created by C++ executable and it will be present on the end user machine.

How can I achieve this?

Thank you


Solution

  • You basically have two options:

    • You attempt to manipulate Firefox data (file cookies.sqlite) directly. It's a fairly simple SQLite database so there is nothing complicated about that. However, catch 1: this cannot be done while Firefox is running. Also, catch 2: the format might change in future (as happened before) and your application will stop working or, worse, break the file.
    • You do it from inside Firefox. For example, you would write a bootstrapped extension that would use nsICookieManager2 interface to add the cookie and then Add-on Manager API to uninstall itself immediately after that. Then your application would only have to run Firefox with the command line firefox -url file:///path/to/extension.xpi (works even if Firefox is already running). The catch here: the user would need to confirm extension installation. So you cannot do it behind his back, you need to explain what is happening and why.