RafaelCT
RafaelCT

Reputation: 95

Error: Components.utils undefined - Firefox Add-on

I am developing a Firefox add-on (using add-on SDK) and I need to use cookies. In order to do that I should import the "Services.jsm" module.

I have followed the instructions from MDN, which advises to use

Components.utils.import("resource://gre/modules/Services.jsm");

I also tried:

Components.utils["import"]("resource://gre/modules/Services.jsm");

When using both I get:

- _errorType = TypeError
- message = Components.utils is undefined

Does any one know how to solve this?

References: Components.utils.import

Upvotes: 4

Views: 4387

Answers (1)

matagus
matagus

Reputation: 6206

When using Addon-on SDK, you have to import it this way:

const { Cu } = require("chrome");
let Services = Cu.import("resource://gre/modules/Services.jsm");

See https://blog.mozilla.org/addons/2012/02/16/using-jsm-modules-in-the-sdk/ for more details.

Upvotes: 1

Related Questions