user1072680
user1072680

Reputation:

read cookies with addon

I am trying to create an addon which after a user logs in to my site I will try and read the session id of that domain and use it for further interactions with my addon. I use the online firefox addon builder, and I tried this example cookies mdn. By using this code it returns me that I don't have the rights to read the XPCComponents.classes:

Fehler: An exception occurred.
Traceback (most recent call last):
  File "C:\Users\tasos\AppData\Roaming\Mozilla\Firefox\Profiles\812iobvo.default\flightdeck\resources\jid0-d0ba10rpeed0a0ftwmx80raes0q-at-jetpack-tasosthegreat-2-data\process.js", line 4, in 
Error: <https://builder.addons.mozilla.org> wurde die Erlaubnis für das Lesen der Eigenschaft XPCComponents.classes verweigert.

Is it the right code to use with the online addon builder?

This is my whole code till now:

main.js:

var data = require("self").data;

var cm = require("context-menu"); 
cm.Item({   
     label: "My Menu Item",
     contentScriptFile: data.url('process.js') 
       });

and process.js:

self.on("click", function (node, data) {


        var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);  
    var uri = ios.newURI("http://www.google.com/", null, null);  
    var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);  
    var cookie = cookieSvc.getCookieString(uri, null);  
});

Upvotes: 3

Views: 1555

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57651

Add-ons built with the SDK cannot access Components.classes directly. Instead they need to use the chrome package:

var {Cc, Ci} = require("chrome");
var cookieSvc = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);

Cc stands for Components.classes, Ci stands for Components.interfaces.

Upvotes: 5

Related Questions