I'm doing this (Firefox 66.0.5, MacOS):
var prefs = Components.classes['#mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
var x = pref.getCharPref('extensions.foo.x');
I'm getting this:
JavaScript error: moz-extension://9390a488-d749-d140-91b6-fb1b2a86053f/foo.js,
line 1: TypeError: Components.classes is undefined
What is the right way to read the preferences of the profile?
I tried this:
var prefs = Components.classesByID['#mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
And got this:
JavaScript error: moz-extension://ebac8f96-717d-0c4b-b2d3-a7d6f3515843/auth.js,
line 1: TypeError: Components.classesByID is undefined
WebExtensions are very limited in their ability to make changes to user preferences. There are a few, currently 14, that you can affect through the browserSettings API. There are others which are effectively changed through other WebExtension APIs (e.g. proxy), but nothing directly. Unfortunately, there's no direct way to read or set user preferences from a WebExtension. The capability to adjust user preferences directly was only available to the older styles of add-ons (all removed as of Firefox 57).
As to your use of Components and the specific errors which you are getting, please see my answer to Unable to use Components in WebExtensions: get “ReferenceError: Cu is not defined” for more detail. The use of Components is just not possible in a WebExtension.
The only way that I can think of that it might be possible to adjust preferences in a release version of Firefox is to use Native messaging to communicate to a native application which you also install. After Firefox exits/stops/is shutdown, the native application could read and change the configuration files in the profile directory for the Firefox profile being run. It could then restart Firefox.
In the Nightly and Developer Edition versions of Firefox, it should still be possible to use a WebExtensions Experiment, which would permit you to make the preference changes you desire using the Components interface. However, that's not a viable solution if this is an extension you want to distribute publicly.
Related
I am quite surprised I have yet to find an answer to this on the internet.
How do I open a native/default app from my nativescript app?
In this instance I want to open a map application with a location parameter (not sure if it will be a string, coordinates, etc).
You can use utils
var utilsModule = require("tns-core-modules/utils/utils");
utilsModule.openUrl("<< for example: maps short link>>");
In fact it will try to open map link with browser. But android && ios will ask to you “do you want to open it via Maps?” at first.
There may be some plugins for opening via maps directly without any question but I think this way is better (you dont need to install a plugin)
For more info about utils, see that
I am running Google Chrome Version 61.0.3163.100. I previously was running the Sense (Beta) extension version 0.9.4 until Google Chrome flagged it as malware in the extensions tab. The author of Sense has removed it from the Chrome store and it has been rolled into Kibana and renamed Console.
Problem is all the queries I wrote in the Sense console are not retrievable due to the extension being disabled. Previously, every time I opened the Sense (Beta) extension, all my previous queries would be saved and re-displayed each session. I would like to find the file location where Sense stored my queries for redisplay.
I am running Windows 10. I have tried locating my saved data by going to:
C:\Users\Admin\AppData\Local\Google\Chrome\User Data\Default\Extensions
There is nothing identifiable I can find that resembles my old data. Does anyone know where I can retrieve it?
Please download this zip file from my dropbox and follow the instructions to install it. Please run the file through some anti-virus to protect yourself. Thanks to this link to help me export chrome extension.
List item Download and unzip attachment
Go to chrome://extensions
Delete the current Sense plugin installed
Check developer mode and click on "Load unpacked extension..." and select the unzipped folder.
It seems like in the case of the Sense extension, its only persistent data was kept in localStorage (relevant source).
Whether data recovery will be easy depends heavily on when you last used the extension.
If you last used the extension before Chrome 61 (~ September 2017), then you are in luck: the localStorage database is stored in SQLite 3 format.
You need to find the corresponding chrome-extension_[some_id]_0.localstorage file under Local Storage in your profile; it's an SQLite database. The ID doesn't seem to be the same as the extension ID.
You can load it in various tools, including sqliteonline.com for an online browser.
If you need data since update to Chrome 61, you're in a much tougher situation. Chrome 61 switched to LevelDB for localStorage backend, and I couldn't easily extract the data from it.
See this question for subtleties involved. The database itself is located at Local Storage/leveldb in your profile.
It seems like Chrome does not delete older SQLite-formatted data, so you can recover at least data from early September.
FWIW, the ID of the extension appears to have been lhjgkmllcaadmopgmanpapmpjgmfcfig
You can copy your Chrome profile to your ChromiumPortable profile then your Sense extension will be enabled in Chromium with all your history.
Chrome profile
C:\Users\xxxx\AppData\Local\Google\Chrome\User Data\Default
Chromium Profile (rename existing profile to Default.bak)
C:\ChromiumPortable\Data\Chromium\UserData\Default
I had the same problem and the above fix got me my Sense history. I am using Chrome 63 and Chromium 65.
Update: Just updated to Chrome 79, this no longer allows me to load addon.
Just updated my Chrome to 69, It disabled my Sense (beta) addon with a "Malware" message, and I thought I lost all my data. The solution is pretty simple.
Go to chrome://flags/#extension-content-verification flag settings by setting as Enforce Strict, changing it to Bootstrap.
This let me load the extension, and all my saved queries were there.
To identify the extension you need to open chrome://extensions/ and check "Developer mode" (on the top right), then scroll down to the extension and you'll find the Extension's ID.
Folder under C:\Users\Admin\AppData\Local\Google\Chrome\User Data\Default\Extensions will be named with Extensions' IDs.
So the story is like this. I debug a site which throws a lot of warnings:
Strict-Transport-Security: The connection to the site is
untrustworthy, so the specified header was ignored.
That is because there is no proper certificate for localhost. But that is very annoying and I was not able to find option to filter out firebug console. So I decided to go into code. I found that firebug is inside ~/.mozilla/firefox/blablabla.bla/extensions/firebug#software.joehewitt.com.xpi and that is zip which I could open with Vim and got to content/firebug/console/errrors.js, find there a variable pointlessErrors and append my message to it.
Firefox ignores changes but after I restart it, it gives me message that firebug was not verified and was disabled. I's probably good, because it will protect me from lot's of risks, but I'm sure in my changes.
How to tell firefox that? Or how to properly make changes to plugins?
Or is there some option for Firefox to shut up about Strict-Transport-Security? (I know, I know, too many questions in one question, but I want to find best solution).
The answer to your question's title can be found in the Mozilla wiki:
There it says:
How do I get my add-ons signed if they are not hosted on addons.mozilla.org (AMO)?
You will need to create an AMO account and submit your add-on. There will be an option where you indicate the add-on won't be listed
on AMO, and you'll be able to submit your add-on files without having
them published on the site. Please read the Distribution Policy for
more details.
You can also use the jpm sign command to generate a signed XPI that can be self-hosted.
There is an API you can use for signing.
Having said that, there are easier alternatives to signing the extension:
Go to about:config and set xpinstall.signatures.required to false.
Install the Nightly, Developer Edition or unbranded version of Firefox
Here's the related answer from the wiki:
What are my options if I want to install unsigned extensions in Firefox?
The Developer Edition and Nightly versions of Firefox will have a setting to disable signature enforcement. There will also be
special unbranded versions of Release and Beta that will have this
setting, so that add-on developers can work on their add-ons without
having to sign every build. To disable signature checks, you will need
to set the xpinstall.signatures.required preference to "false".
type about:config into the URL bar in Firefox
in the Search box type xpinstall.signatures.required
double-click the preference, or right-click and selected "Toggle", to set it to false.
Regarding the question about getting rid of the warning regarding Strict Transport Security I see a few other possible solutions:
Access your localhost via HTTP instead of HTTPS.
Suppress sending the Strict-Transport-Security header on localhost.
Install a proper certificate.
Note that this warning is shown for security purposes, so there is some risk in disabling it generally.
I want to save user settings for my firefox add-on in a variable which can be accessible any time I want. It should not get vanished on browser clos. Now how can I do it?
I have tried "simple-storage" module of firefox, it works fine until I quit my browser. When I quit my browser, "simple-storage"s wipes out. So I can't use it.
I have also tried "io/text-streams" module but when I try to use this module in "firefox add-on builder"
var io = require("io/text-streams");
io.write("write it");
I am getting this error:
XPI not built
ModuleNotFoundError: unable to satisfy: require(io/text-streams) from /tmp/tmpePRdMr/addon-sdk-1.12/packages/sadaf2605-4/lib/main.js:2: Looked for it in: /tmp/tmpePRdMr/addon-sdk-1.12/packages/sadaf2605-4/lib/io/text-streams.js /tmp/tmpePRdMr/addon-sdk-1.12/lib/io/text-streams.js
Most probably, I would need to install some packages, do the user who will be using my add-on, do they also need to install those packages on their browser?
Apparently you are testing your add-on with cfx run. The documentation explains why simple-storage appears broken and how to solve it.
Try saving your settings in localStorage object (HTML5) .Your values wont vanish after the session is closed ......
I understand that I can log to the console when using a Firefox extension with the cfx run command.
Is there a way to log to a console after the extension has been packaged with cfx xpi? Logging to Firebug is fine if possible.
I have found two blog posts about this (here and here). Both are rather old and don't work any more.
I'm using version 1.10 of the add-on SDK and FF15.
You need to do 2 things:
enable logging for addons
• in about:config, add a new option extensions.sdk.console.logLevel and give it the value "all"
• restart Firefox
in Firefox open the Browser Console:
• Tools -> Web developer -> Browser console
• NOTE: this is different from the usual Web Console used to debug web pages
You should see addons logs there now.
TLDR:
Go to about:config url and create key extensions.sdk.console.logLevel with value all
See log messages either in Browser console (Ctrl+Shift+J) or in terminal you started Firefox from.
cfx or its successor jpm creates this configuration key automatically in development firefox profile.
From logging documentation:
extensions.sdk.console.logLevel: if set, this determines the logging level for all installed SDK-based add-ons.
extensions.extensionID.sdk.console.logLevel, where extensionID is an add-on's Program ID. If set, this determines the logging level for
the specified add-on. This overrides the global preference if both
preferences are set.
I will summarize recent changes that has taken with Firefox since this question got posted -- basically updated #LucaBonavita answer.
In about:config, check if option extensions.sdk.console.logLevel is enabled. If not, toggle to enable. You might need to create it if it does not exist
Open Browser Console
Menu Bar -> Tools -> Browser Tools -> Browser Console
Enable Show Content Messages in browser console.
Now, console.log triggered by Firefox addon/extension should display
Tested on Firefox 94.0.2 (64-bit) and 95.0b12 (64-bit)
Have you tried console.log() with Firebug? (I know you have tried Application.console.log() and Firebug.console.log() already)
I just tried it in the Web Console on FF16 running Firebug 1.10.4 and it seems to work:
Here are some more examples from the Firebug Wiki itself: FirebugWiki Console API
Additionally, you can write messages of different types in the console, such as: console.debug(), console.info(), console.warn(), console.error()
If you run console.log from Add-on code, it send up in the 'Messages' tab of the Error Console window: