开发者

Firefox - how do I list installed extensions and identify them in a list?

Two related questions:

  1. I开发者_C百科s there an API to produce a list of all the installed extensions in Firefox?

  2. If so, how would I uniquely identify an extension? What I need is to have an ID that persists through different versions of an extension and ideally through a renaming (so name may not be the best option). Is it GUID?

Thanks!


Note: this answer is outdated. nsIExtensionManager was replaced by AddonManager, and FUEL is deprecated.

You can get the list of items from nsIExtensionManager. Yes there is a unique ID for extensions (nsIUpdateItem::id), as specified in the install manifest.

On a second thought, this is where FUEL is really useful. Try this in the Error Console:

Application.extensions.all.forEach(function(item) { alert(item.id) })


To get extensions list, Please take a look at nsExtensionManager.js in components folder, there is a variable called validExtensions which use to generate extensions.ini in firefox profile directory

For unique ID, I guess its depend on extensions itself, because some extensions like noscript, adblockplus use GUID, and some extensions like firebug,foxmarks using email address style.


From outside of Firefox (in version 60.0 at least) the installed extensions list can be obtained from extensions.json file in profile directory. There can be also found extensions.sqlite and addons.sqlite sqlite databases, but they don't cover all the extensions. There is also addons.json but it does not contain 'active' flag (i.e. whether extension is active, enabled or disabled).

To get CSV-like list of installed extensions with type and active flag the following XPath3 query can be used:

( json-doc("extensions.json") ? addons ? * )
  ! (( ?type, ?defaultLocale ?name, ?active )
    => string-join(",") || "
" ) => string-join()

Output example:

extension,Mozilla Archive Format,false
extension,Restart,false
theme,Default,false
webextension,Add HTTPS,true
webextension,Greasemonkey,true

NB: for a correct CSV it also needs to wrap with quotes the values containing comma or quotation mark and escape the quotation marks.

From a shell, using xq command, and with filter for active extensions:

xq ' ( json-doc("extensions.json") ? addons ? * ) [ ?active eq true() ] 
  ! (( ?type, ?defaultLocale ?name, ?active )
    => string-join(",") || "
" ) => string-join() '

Output example:

webextension,Add HTTPS,true
webextension,Greasemonkey,true

xq script:

#!/bin/bash
declare_ns_map='declare namespace map = "http://www.w3.org/2005/xpath-functions/map";'
declare_ns_array='declare namespace array = "http://www.w3.org/2005/xpath-functions/array";'

q="$1"; shift
saxonhe-xquery -qs:"$declare_ns_map $declare_ns_array $q" "$@" \!omit-xml-declaration=yes \!indent=yes

saxonhe-xquery script (a wrapper for Saxon XQuery):

#!/bin/sh
exec java -classpath /usr/share/java/Saxon-HE.jar net.sf.saxon.Query "$@"

Update

A slightly simpler query than XPath to get the same result using jq JSON processor:

jq -j '.addons [] | ( .type, ",", .defaultLocale.name, ",", .active, "\n" )' extensions.json | sort

Output only active extension and generate output in CSV format (using @csv filter):

jq -r '.addons[] | select( .active == true )
  | [ .type, .defaultLocale.name, .active ] | @csv ' extensions.json

A similar select via the jj (manual), but without an ability to have output in a plain text format (i.e. not JSON):

jj -i ./extensions.json 'addons.#( active == true )# 
  .[type,defaultLocale.name,active] .@pretty'


For documentation and backup purposes, I wanted a list of all the extensions I installed, including a link to its page at addons.mozilla.org so I could easily reinstall them if necessary.

First, cd into the firefox profile directory. For example:

cd ~/.mozilla/firefox/juxa1m2n.default-1644874267533

The addons.mozilla.org site is internationalized. When creating the URLs we need to embed our preferred language code. To prepare for this, we set a variable, lang, to the language portion of our LANG environment variable:

lang=$(grep -Eo '^[^.]*' <<<"$LANG")

Then use jq to list your enabled or disabled extensions that you installed.

List enabled firefox extensions

jq --arg lang "$lang" -j '.addons |
   map(select(.type == "extension" and .location == "app-profile" and (.userDisabled | not)))
   | .[] | "- [",.defaultLocale.name,"]",
     "(https://addons.mozilla.org/\($lang)/firefox/addon/",(.id|@uri),")\n" ' \
  extensions.json

Result in my case:

- [Open in Browser](https://addons.mozilla.org/en-US/firefox/addon/openinbrowser%40www.spasche.net)
- [Bookmarklets context menu](https://addons.mozilla.org/en-US/firefox/addon/%7B8d2a1b8a-2ff6-4bde-aae4-4a9dd54b7e66%7D)
- [ContextSearch web-ext](https://addons.mozilla.org/en-US/firefox/addon/%7B5dd73bb9-e728-4d1e-990b-c77d8e03670f%7D)
- [Export Cookies](https://addons.mozilla.org/en-US/firefox/addon/%7B36bdf805-c6f2-4f41-94d2-9b646342c1dc%7D)
- [Wayback Machine](https://addons.mozilla.org/en-US/firefox/addon/wayback_machine%40mozilla.org)
- [Duplicate Tab](https://addons.mozilla.org/en-US/firefox/addon/%7B54fa1e34-a0ad-4526-a81b-b06139adf332%7D)
- [Reader View](https://addons.mozilla.org/en-US/firefox/addon/%7B2495d258-41e7-4cd5-bc7d-ac15981f064e%7D)
- [FaviconSwitcher](https://addons.mozilla.org/en-US/firefox/addon/%7B1220100b-db8f-419f-9cd4-ed7a51cee7f3%7D)
- [Display #Anchors](https://addons.mozilla.org/en-US/firefox/addon/display-anchors%40robwu.nl)
- [CopyTabTitleUrl](https://addons.mozilla.org/en-US/firefox/addon/CopyTabTitleUrl%40bugbugnow.net)
- [Stylus](https://addons.mozilla.org/en-US/firefox/addon/%7B7a7a4a92-a2a0-41d1-9fd7-1e92480d612d%7D)
- [Nuke Anything](https://addons.mozilla.org/en-US/firefox/addon/%7B1ced4832-f06e-413f-aa14-9eb63ad40ace%7D)
- [New Tab Beside](https://addons.mozilla.org/en-US/firefox/addon/%7B93c2f785-16bd-49fa-91f3-6a28a8f0d7f9%7D)
- [AlwaysSmile](https://addons.mozilla.org/en-US/firefox/addon/alwayssmile%40mozilla.org)

I formatted it as a list of links using Markdown syntax. You can paste it into a Markdown document.

List disabled firefox extensions

jq --arg lang "$lang" -j '.addons | map(select(.type == "extension" and .location == "app-profile" and .userDisabled)) | .[] |
   "- [",.defaultLocale.name,"](https://addons.mozilla.org/\($lang)/firefox/addon/",(.id|@uri),")\n" ' extensions.json
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜