0

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

dpb
  • 353
  • 4
  • 15
  • This can't be good at all. If you need cookie access/control it should come from the web not an application. This is spyware, adware, or limitware at its ugliest no doubt. Can't trust an app that wants to manage "its own cookies" locally. No way no how. –  Mar 31 '12 at 07:08
  • You are asking for access to a private database sir. When there is obvisously several thousand different ways to achieve 'an appreciable' result without mining through private data. –  Mar 31 '12 at 07:11

1 Answers1

2

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.
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • The C++ exeutable needs to be in touch with Firefox since it has to update/remove cookie from time to time depending on different conditions. For example if user is idle for 5 mins the C++ executable should remove this cookie. I was thinking of using SPIDERMONKEY this way whatever JavaScript will be executed it will be inside FireFox. But not sure if it will work. – dpb Mar 28 '12 at 09:30
  • To execute something "inside Firefox" you need an extension, see option 2. That's the only option if you need to know what is happening inside Firefox. – Wladimir Palant Mar 28 '12 at 09:34
  • Sorry, but I am a newbie on Firefox. I did not get how to maintain communication between by C++ executable and Firefox. If you can point me o some tutorial on simple bootstrapped extension it will be of great help. – dpb Mar 28 '12 at 09:41
  • Got the link to extesion tutorial. I am struck on how I will signal this extension from C++ executable to do different tasks like a) Add cookie b) Remove cookie c) update it – dpb Mar 28 '12 at 09:54
  • I guess firefox extensions are out for me, thanks to sir-hacks-alot and the gullable crew. lol - just sayin.. that's my two cents on cookies.. HANDS OFF. Use a flat text file for local data storage or a private authentication scheme to verify site authentication if that's what you are after. Beyond that this question and the answers to it are totally malicious. –  Mar 31 '12 at 07:17