Firefox addon development, how to change about:config setting

孤人 提交于 2021-01-27 10:34:01

问题


Hi I'm trying to develop a simple addon which opens a web page different from firefox default page in new tab. I want to change two of the default settings values in about:config, but it seems I cannot achieve this through my current configuration.

I'm using the Add-On SDK recommended by firefox to develop the add-on.(creating a simple add-on using the SDK

By looking into the about:config setting, I found that if I set "browser.newtab.url" to the web page url, and "moa.ntab.openInNewTab" from true to false, I can realize such function. So I followed the tutorial above and added ./defaults/preferences/pref.js for changing the config.

My current directory looks like this:

ff-addon
  └─ data
  └─ defaults
     └─ preferences
        └─pref.js
  └─ lib
     └─ main.js
  └─ package.json
  └─ test
     └─ test-main.js

the pref.js code in the /defaults/preferences directory is as follows:

pref("browser.newtab.url", "http://www.baidu.com");
pref("moa.ntab.openInNewTab", false);

I did not change the code in main.js. Code of it is shown below:

var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");

var button = buttons.ActionButton({
  id: "mozilla-link",
  label: "Visit Mozilla",
  icon: {
    "16": "./icon-16.png",
    "32": "./icon-32.png",
    "64": "./icon-64.png"
  },
  onClick: handleClick
});

function handleClick(state) {
  tabs.open("http://www.mozilla.org/");
}

I did not change the code in package.json either:

{
  "name": "ff-addon",
  "title": "ff-addon",
  "id": "jid1-mPDAO4AqY5w17w",
  "description": "a basic add-on",
  "author": "",
  "license": "MPL 2.0",
  "version": "0.1"
}

Could you please tell me what's wrong or maybe what I can follow in finishing such simple functions... Thank you so much!


回答1:


As the first comment says, see the documentation for sdk/preferences/service.

Here's a quick example:

var name = "extensions.checkCompatibility.nightly";
require("sdk/preferences/service").set(name, false)


来源:https://stackoverflow.com/questions/29194144/firefox-addon-development-how-to-change-aboutconfig-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!