Buttons not showing up in Firefox WebExtension notifications - javascript

I am working on a Firefox WebExtension in which I am trying to display a notification with a button. I have this working in Chrome. According to the docs, this is supported in Firefox. Buttons are listed as Optional in the NotificationOptions.
chrome.notifications.create(notificaitonId, {
type: "basic",
iconUrl: chrome.extension.getURL("images/unknown.svg"),
title: "Blah",
message: "A Message",
buttons: [{title: "Get More Details"}]
});
When I run this code, I see the notification. But, I don't see a button. Am I missing something? Is it actually not supported? The only example for notifications doesn't use buttons so that hasn't been helpful.

Unfortunately, buttons are not, as of 2016-03-18, implemented for WebExtension notifications.
The NotificationOptions documentation on MDN states [emphasis/formatting mine]:
The first four properties - type, iconUrl, title, message - are
mandatory in notifications.create(), and optional in
notifications.update(). Firefox currently supports only these
four properties.
and in the Browser compatibility section:
Firefox only supports: type, iconUrl, title, message.
The important parts of this ("Firefox currently supports only these four properties" and Firefox only supports: type, iconUrl, title, message.) were added to the documentation on 2016-03-07. Thus, if you looked at the documentation prior to that date there would have been no indication that buttons was not yet implemented.
In addition, the source code has the comment:
// FIXME: Lots of options still aren't supported, especially
// buttons.
You can also find the source code that is currently in use for this in your browser at: chrome://extensions/content/ext-notifications.js
Solution: Implement buttons yourself:
In WebExtensions:
It might be possible to implement buttons yourself from within WebExtensions. However, I am not familiar enough with WebExtensions to be able to say if it is possible, or not. If so, you will probably want to take a look at the source code that implements notifications and notification buttons for other types of Firefox add-ons.
For Firefox, generally:
If it was something I needed, I would probably choose to go ahead and implement buttons, and any other options I needed, for the entirety of Firefox and submit the code to Mozilla for review and inclusion in Firefox. I know this might sound like it is a big deal and a pain in the rear, but it really shouldn't be that difficult.
If you do desire to work on it, it should not take any special setup. The JavaScript code which implements notifications for WebExtensions is the file ext-notifications.js which is contained in the chrome\toolkit\content\extensions directory within the omni.ja file (just a .zip file with the extension changed to .ja) which is located in the Firefox install directory. Note there are actually 3 different omni.ja files within the install directory hierarchy. The one you want is in the root of install hierarchy, not the ones in either the browser or webapprt sub-directories.
Working on it would be as simple as extracting that file, modifying it, making an updated omni.ja file and putting the updated omni.ja file into the release directory. For a while, I did this routinely upon every release of Firefox because I wanted a longer bookmark MRU file list. I eventually broke down and just made an overlay extension, Change Bookmark Recent Folder List Length, to replace the file I was making changes to. If you want, you could do the same thing to implement the changes needed to support buttons. That would, of course, result in your current extension being dependent on the other one being installed until such time as the code was integrated into Firefox. But, it would result in both your having the functionality you desire now for your development, and the functionality getting into Firefox at least somewhat faster than waiting for someone else at Mozilla to implement it. An overlay extension like that just takes a install.rdf file, a two line chrome.manifest file and the updated ext-notifications.js file you are wanting to override/replace over the current one.

Related

Ability to load init script in Firefox?

I have a long time stick with Conkeror as my default web browser and get used to configuring/adding new features to my browser using js code with all the XUL Api through the .conkerorrc file. I'm migrating to Firefox since it has better support and is actively maintained by Mozilla. However, one of the feature that I've been missing so much is the dot file, which I can easily configure anything that I like, back up all of them through git and eval the code directly (using Mozrepl) while I'm coding to see the result.
Is there any way that I can inject/execute a sciprt on Firefox startup, for example ~/.firefox/index.js?
There is no functionality in stock Firefox to execute JavaScript code supplied by the user at startup. Functionality like this has been something that has been requested of Firefox since 2006-04-02.
It is trivial to write an add-on in any of the different Firefox add-on types (XUL/Overlay, Restartless/Bootstrap, Add-on SDK, or WebExtensions) which would run whatever JavaScript you desire upon Firefox startup. This could be done to either run code that was included in the add-on (simple), or that runs the JavaScript contained in a file that is loaded from a location external to the add-on (more complex). Which add-on type you used to implemented this would impact which interfaces you had available within the code you write. One drawback of writing your own extension which runs code included in the add-on is that in order to use it with a release, or beta version of Firefox is that you would need to have it signed by Mozilla. While this is a quick and easy process, it does add some additional overhead to the development/test cycle.
You have not specified any of the firefox-addon tags in your question. In addition, you have not described the functionality you desire, except as generalities. It also does not appear to be the intent of your question to ask how you would implement such an add-on. Given those and the fact that there are already multiple add-ons that implement the functionality of running arbitrary JavaScript (including XUL) code supplied by the user, I am not going to supply code here which performs this function.
However, if you are interested in using an already existing add-on, here are a few options:
userChromeJS: This extension was derived from the code originally provided as an example of how to implement the functionality requested in bug 332529. Its first feature listed is: "Complete chrome customization is possible by running custom javascript code or overlaying chrome with .xul overlays." This is an Overlay based add-on with which you can use XUL. This sounds like the functionality what you are interested in obtaining.
uc: "A userChromeJS clone with built-in subscript/overlay loader capability."
Greasemonkey: "Customize the way a web page displays or behaves, by using small bits of JavaScript." This is a commonly used add-on which permits writing more complex JavaScript code. The code is executed in a sandbox, not in the scope of an extension. This is done for security reasons.
Custom Style Script (Inject desired CSS or JS): "Add Custom JavaScript Codes or Styles (CSS) to an specific page or all pages."

Programmatically update firefox profiles

Windows 7 / Firefox Latest versions / Preferrably 64bit beta versions
Whenever a Firefox Profile is updated, the user is presented with a dialog to check for updates to the addons. I would like to interact with tha dialog programmatically so that it is automatically ok-ed.
So far my research has brought me to:
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator
For that I need a windowtype to enumerate. The window type correspons to the attribute in the XUL definitions. On my installation of Firefox, these seem to be compressed inside "c:\Program Files\Mozilla Firefox\browser\omni.ja\chrome\browser\content\browser".
I have limited experience of the firefox API. I'm executing code through userchrome.js.
Any pointer would be gladly received.
UPDATE 1 20151125 0748: I believe this is the xul - https://archive.is/NyGBS - any pointer on how to "overlay" it within userchrome.js? I can also try to enumerate windows of windowtype="Addons:Compatibility".
UPDATE 2 20151125 0748: It looks like the extensions update dialog is not showed if I have:
user_pref("xpinstall.signatures.required", false);
Which marks the addon as unsafe but allows you to continue using it.
[Which solves my immediate problem, but I am sure I will have this requirement at another point for another dialog, so would still like to get to the bottom of this]
TL;DR version with info about the problem follows.
I currently have a vbs script that:
Deletes FIREFOX_RUNNING_PROFILE folder.
Copies FIREFOX_BASE_PROFILE folder-> FIREFOX_RUNNING_PROFILE folder.
Runs FIREFOX_RUNNING_PROFILE.
Whenever a firefox update takes place, a number of dialogs need to be confirmed by the user in relation to checking/updating extensions.
The outcome of this process will not stick to the profile as obviously given my setup the RUNNING_PROFILE is recreated every time.
Note that for the purposes of this discussion it doesn't matter whether the udpate is performed automatically. I have the ability to rewrite the prefs.js so i can change behaviour dynamically just by doing that and restarting the browser externally - it's vbs right now but I'm ready to move over to something else if I hit some limitations with process / window management, or I want this to be portable (e.g. python). Note these are not dealbreakers right now and I'd be happy for a reasaonbly sleek windows-only solution.
I have a few of this BASE_PROFILES, hence I would like to handle the updates programmatically.
I have not found a way of achieving this that does not involve interacting with the dialogs firefox presents in the GUI. And I have noticed that the dialogs popping up after each update can change.
Options:
1) userchrome.js -> I already use this to manage some imacros autostart features, including grabbing the profile name from Components.Interfaces. I am reporting snippets below to help the reader understand what is the most sophisticated snippet I've written against the Mozilla xpcom components:
var strProfileFilePath=Components.classes["#mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path;
I have had a look at the documentation and it looks rather impressive. It feels like it will let me do pretty much everything, so my next move here would be to undersrtand how to enumerate dialogs and somehow select the right one based on some properties, then push the "ok" button. I think that's pretty much all I need to do.
2) Autohotkey. I can try and send keys to the firefox window (not sure about the exact dialog inside the window). The dialogs normally have shortcuts that would respond to those to this keysends (nice theory). In autohotkey I can also "position-click", although it is less desirable for obvious reasons.
3) One of the avenues through Autohotkey involves using the MozRepl Firefox addon behind the scenes. Library discussed here https://archive.is/73u4f, github seems out of date https://github.com/arbiter34/FF-Control. I could then use mozrepl directly, no need for Autohotkey. I would rather code in python, java, or even javascript, powershell, vbs than autohotkey. Ar a first look it looks like it would give me the same power that userchrome.js currently offers.
4) Selenium. There are some profile manipulation capabilities I could exploit - although Selenium was not really designed to interact with Firefox own's dialogs, and I don't see an API to automate that. Rather one would synthesise a profile on the fly, installing on top all the required extensions from a known superprofile (that would contain a superset of all the extensions to be used), and applying whatever mods to prefs.js also dynamically. This sounds a bit ugly for my original requirements but experience has told me that ugly is still better than manual.
5) There is also the option of writing an addon, but again, I think I'ld be interacting with the same interfaces that I can get in userchrome.js (actually I believe userchrome.js is even better as it seems to have unfettered access to the core components, which is exactly what I sense I might need for my case). I would rather avoid having to write an addon, although I might be lost for words trying to explain why exactly.
I appreciate I have not "fully" investigated further, but I am at a point now where I need to elicit the opinion of the community before I start spending substantial time on either of these.
The below isn't strictly required to address the question above, but I feel it might be useful to share this as there must be a few others undergoing the same predicament:
Additional Points:
a. As a general principle, I have zero desire to update anything (firefox.exe, addons, language packs, plugins and what not) (plugins are actually completely disabled). I am ok with the way the system works, and I don't want to change it one millimitre. Yes, NOTHING, not even the security updates. This is because of the particular circumstances of my app, my particular estimation of the particular risks I'm taking, and my general aversion to risk. YMMV. NEVERTHELESS I'm still forced to upgrade whenever (1) I "make a mistake" (all it takes is for one profile to have the update settings wrong for the exe to be updated for all the profiles on the machine - doh! there's only one exe); (2) Firefox is crashing too much / unusable (happened twice); (3) I need functionality offered by the upgrade (hasn't happened); I would also like to reserve the option for the "very critical security updates" (sigh! sometimes even I can bow).
b. The arcane art of keeping your firefox profile integer across updates also involves search engines - it doesn't matter if I say I don't want to update them, whenever there's a firefox.exe update I will get the new standard fluff installed in the program folder. I currently have a way of resetting that by (1) emptying the firefox program subfolder containing the xml files (in %programfiles%\Mozilla...), and (2) deleting search-metadata.json and the searchplugins folder (in the profile folder), then copying them over from a baseline afresh. It all feels very greasy. I have yet to try this on the 64bit version I'm running right now as this is a minor issue and I would rather not introduce more entropy. The firefox search engines mechanism might have changed in the meantime.

Errors in Firefox Add-on SDK when using cfx xpi whereas cfx run works great

I'm a student at a University Institute of Technology in France and I'm very new to Firefox add-on development since I discovered it at the beginning of my work placement, a few days ago.
What I have to do is an add-on that allows employees of the company to organize SCRUM-meetings (it deals with agile software development).
For the moment, what I've done looks like this :
http://img11.hostingpics.net/pics/716589MeetingConfigurationPanel.png
The panel allows users to configure the settings of the meeting. I have also added a toolbar with action buttons and a frame in it, so that the meeting can start/be interrupted on the action buttons Onclick event. I have implemented countdown timers for each participants. There is also a "Next Speaker Button" that resets one of the timers when clicked...
And all seems to work fine when I use cfx run, but when I package the extension using cfx xpi... there are errors.
See : http://img11.hostingpics.net/thumbs/mini_585083outputExpected.png
EDIT : Problem with the link. I will update it as soon as possible.
Here is what I have in cfx run mode. All the buttons I declared in the code, along with the frame, are correctly displayed in the toolbar.
But in cfx xpi mode, some of the buttons are apparently "stuck" in what Browser Console refers to as "inner-toolbar" or something like that as I can read when I remove the extension.
That made me wonder if the buttons really were in the toolbar. And they were, according to the Debugger. So I've started thinking that my problem was compatibility with Firefox but I've checked both Firefox version and the em:maxVersion attribute in the install.rdf file that can be found when unpacking the xpi/zip file, and I've change the values so that they match, but it didn't resolve my problem.
I've read as many things as possible on topics related to the problem I'm now facing (including StackOverflow questions) but I have not been able to find a proper way to fix it up to now. Is my problem really different ? I have no idea. I might have done something bad trying to change things as they were intended to, I suppose. But it's unlikely.
And the thing is that I really need to make this add-on works, because it is the only thing I will work on during my work placement.
The solution to my problem may be very simple. Maybe I did something really stupid. I don't know. The only thing I know for sure is that I want to find what's going on, so that I will be able to deliver the first version as soon as possible.
Feel free to ask for more informations if necessary.
Thanks for reading.
Julien B.
(Not technically an answer but SO won't let me comment.) You could try cfx run, then uninstalling the addon from the FF session it opened, then installing the xpi in that same session by doing a file open of the xpi (which will install it). Have a feeling it will run in that case, which means there is a difference between your standard Firefox and the one cfx run opens. There is a difference of course, because cfx run doesn't install all your other add-ons. But it may be running a different Firefox version as well. I mention this because when I run cfx run it always opens the beta version of FF which I downloaded at some point, and I don't know where its picking it up from.

FireFox. How to create a bootstrap extension?

It isn't a coding question(I think :)). I have read manual about how to add bootstrap in to my FireFox extension, but what doing next?
I added bootstrap.js, modify install.rdf, what to do next?
What I need to do wiith my files in content folder?
My extension structure:
./chrome.manifest
./Icon.png
./Install.rdf
./chrome/content/Overlay.xul
./chrome/content/Overlay.js
./chrome/content/Options.xul
./chrome/content/Options.js
./chrome/content/Window1.xul
./chrome/content/Window1.js
./chrome/locale/<locales>
I written FireFox extension that's need browser restart, but restart isn't needed for extension work. I want remove that action, and I found something about bootstrap.
I think, now I need manually (un)register my windows, overlays, locales, where read about that?
Please, give me more info, url, links, how to modify my extension into bootstrapped.
Some chrome.manifest directives, e.g. chrome, skin, locale, are supported in bootstrapped extensions, so nothing special you need to do there.
Overlays are not supported, however. You need add some code that will use the DOM APIs to manually insert and/or change elements you normally would have in your overlay.
The "Further reading" section of the docs you already linked contains some stuff. Most bootstrapped add-ons I encountered use some variation of the watchWindows stuff.
It might be also helpful to look at real world examples, such as Restartless Restart (which happens to be rather small, and easy enough to understand).

Clearing javascript cache in ie10 not working, can no longer debug javascript changes

Now that I have upgraded to IE10, it's very difficult to get my javascript changed files to get recognized.
In IE9, you could simply use the 'clear the cache' button in the develepor panel and could see your javascript changes.
This no longer works (apparently) -- is there some other way to get IE10 to dump your cache? This is brutal!
On Windows 7, using VS2010 and just upgraded to IE10.
I think I found out the answer... it appears that IE10 either added (or added this as a default) a setting 'PRESERVE FAVORITES WEBSITE DATA' ... this was checked (by default) and although I havent thoroughly tested it, I think this is why my js files were not being purged.
It's incredibly easy to get bugs due to bad caching. Developing with caching turned on (and manually purging the cache) is mission-impossible.
If you're using a server-side scripting language to generate your page you can use fingerprinting.
You can add a querystring to the URL that is always different, this makes it so browsers will never cache the scripts. Very useful for development, terrible for live :P
Eg: script.js?fingerprint=123456 where 123456 is a different number each page load.
A more involved solution would look at actual changes in the source code.
In my web-based mySQL application, IE-10 (with default settings) often refuses to show the present state of the mySQL database. It usually shows the state of an earlier visit (showing records that were deleted, or not showing records that were added).
This is a consequence of a changeable IE-10 setting. (Unfortunately I have only access to a Dutch-speaking IE-10, MS refuses me to download an English speaking browser). In rough translation: go to Internet options/General. You see "Browsing History" with a button "Settings". Hit it and you will see radio buttons determining the search for fresh pages. The default is "automatic", change it to "search for fresh page on every visit". This fixed my problem
Unfortunately however, I don't know how to set this from within my app, so I have to inform my users about it. This is awkward.

Categories

Resources