Fczbkk
Fczbkk

Reputation: 1467

Open options page of addon using `simple-prefs` from content script

I have an addon using simple-prefs. The addon modifies some webpages using PageMod.

I would like to add a link to these webpages, that will open the addon options. Basically, what I need, is a Firefox version of chrome.extension.getURL('options.html'); used in Chrome.

I have tried some old methods. For example using URL like this: addons://detail/ADDON_ID/preferences. Or this method from official documentation. But none of them seem to work.

How do I do that? Is it even possible?

Upvotes: 1

Views: 172

Answers (1)

humanoid
humanoid

Reputation: 764

First off, you can't open it directly from the content script. You'll have to send a message from your content script to your extension using the port API, which would look something like this in your content script:

self.port.emit("openPrefs");

In your add-on module where you have the reference to your PageMod object (I assume it's saved in the pageMod variable) you'd then open the preferences page using the (undocumented) sdk/preferences/utils module:

var self = require("sdk/self");
var { open } = require("sdk/preferences/utils");
pageMod.port.on("openPrefs", function() {
  open({ id: self.id });
});

Upvotes: 3

Related Questions