[FIXED] CB broken on all Firefox versions higher than 43

Post information about bugs here

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby Odyseus » Fri Feb 26, 2016 9:31 am

Hello, Infocatcher.

I tested the add-on that you posted in your last post (dev3) in Firefox Developer Edition and in Nightly (Both with Electrolysis enabled.
  • In Firefox Developer Edition it works consistently. It installs any CB URI from any source always.
  • In Firefox Nightly it always fails (gives the message The address wasn't understood) the first time you try to install any CB URI from any source. After the first failed attempt, it will try to install consistently CB URIs from any source.
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby Infocatcher » Fri Feb 26, 2016 11:22 pm

Odyseus wrote:In Firefox Nightly it always fails (gives the message The address wasn't understood) the first time you try to install any CB URI from any source. After the first failed attempt, it will try to install consistently CB URIs from any source.

This happens for me in Developer Edition too...
Looks like initialization of old-way nsIProtocolHandler implementation happens too later (or somehow optimized).
Following should fix this (code was moved from components/CustomButtonProtocol.js to components/CustomButtonsService.js that registers itself for "app-startup" notification):
custom_buttons-0.0.5.8.5-e10s_protocol_dev4.xpi
Infocatcher
 
Posts: 123
Joined: Sat Jul 21, 2012 5:04 pm

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby Odyseus » Sat Feb 27, 2016 6:31 am

Tested "dev4" and works perfectly on first attempt to install any CB URI from any source. Thanks, Infocatcher!

Infocatcher wrote:This happens for me in Developer Edition too...

It happened to me too in Developer Edition just once, but could never replicate it. After each browser restart, it started working always on the first try.

Off-topic: Do you think that could be possible to add direct access to the add-on SDK modules to Custom Buttons add-on? So we can use from a button code something like this:
Code: Select all
/*CODE*/
var selection = custombuttonsUtils.require("sdk/selection");

console.info(selection.text);

or...
Code: Select all
/*CODE*/
var {
   notify
} = custombuttonsUtils.require("sdk/notifications");
notify({
   title: "Notification",
   text: "Hello from the SDK!",
   iconURL: "chrome://custombuttons/skin/button.png"
});


Why do this?
For two main reasons. Electrolysis will break a lot of things (getSelection() is one of the things that will stop working) that will only be possible to access/use with frame scripts. Frame scripts are simple enough to use, but if we have to use getSelection() in 10 different buttons for example, we would have to load 10 different frame scripts that will do the exact same thing!!! And, on top of that stupidity, there is the fact that frame scripts still can't be unloaded from existent tabs, so they have to be "randomized". All this forces us to write dozens of lines of code (!!!) when it should be a task simple enough to run using one single line of code.

The second reason would be that, although we can make use right now of the "require" method(?) with this simple enough code...
Code: Select all
/*Initialization Code*/
const {
   require
} = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

var selection = require("sdk/selection");

this.onclick = function () {
   console.info(selection.text);
};

...the "geniuses" at Mozilla keep changing the paths to files!!! Because resource://gre/modules/commonjs/toolkit/require.js doesn't exists in Palemoon and Thunderbird under that path. Forcing us AGAIN to write dozens of lines of code when it can be just one line of code!!!

What I propose
I have been using since a couple of months a function created by Alice0775. I adapted it to add the "require" method(?) into the custombuttonsUtils global object. I simply added to the chrome/custombuttons.jar/content/custombuttons/contextBuilder.js the following function:
Code: Select all
(function() {
   /* This Source Code Form is subject to the terms of the Mozilla Public
    * License, v. 2.0. If a copy of the MPL was not distributed with this
    * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
   const {
      Services
   } = Cu.import("resource://gre/modules/Services.jsm", {});
   const LoaderModule = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader;
   const {
      console
   } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
   let {
      Loader, main, Module, Require, unload
   } = LoaderModule;

   let CURRENT_DIR = getCURRENT_DIR(); //'scratchpad://';
   let loaders = [];

   function getCURRENT_DIR() {
      Error().stack.split('\n')[2].match(/^[^@]*@(.*?)[^/]+:\d+$/);
      let p0 = RegExp.$1;
      let p1 = Error().fileName.replace(/[^/]+$/, '').split(' -> ').pop();
      return (p0 == p1) ? [p0] : [p0, p1];
   }

   function makePaths(root) {
      return {
         './': CURRENT_DIR,
         '': 'resource://gre/modules/commonjs/'
      };
   }

   function makeLoader(options) {
      let {
         paths, globals
      } = options || {};

      // We have to have `console` as a global, otherwise
      // many SDK modules will fail
      // bug 961252
      let globalDefaults = {
         console: console
      };

      let loader = Loader({
         paths: paths || makePaths(),
         globals: extend({}, globalDefaults, globals) || null,
         modules: {
            // Needed because sdk/ modules reference utilities in
            // `toolkit/loader`, until Bug 961194 is completed
            'toolkit/loader': LoaderModule
         },
         // We need rootURI due to `sdk/self` (or are using native loader)
         // which overloads with pseudo modules
         // bug 961245
         rootURI: CURRENT_DIR,
         // We also need metadata dummy object
         // bug 961245
         metadata: {}
      });

      loaders.push(loader);
      return loader;
   }

   function extend(...objs) {
      if (objs.length === 0 || objs.length === 1)
         return objs[0] || {};

      for (let i = objs.length; i > 1; i--) {
         for (var prop in objs[i - 1])
            objs[0][prop] = objs[i - 1][prop];
      }
      return objs[0];
   }

   // clean up
   window.addEventListener("unload", function() {
      loaders.forEach(unload);
   }, false);


   // init codes
   function init_require() {
      // Load `constructor` as global since tabs uses `traits`
      // that use this module
      let loader = makeLoader({
         globals: constructor
      });
      let module = Module("./main", CURRENT_DIR /* "scratchpad://" */ );
      let require = Require(loader, module);
      // window.userChrome.require = require;
      if ("custombuttonsUtils" in window)
         window.custombuttonsUtils.require = require;
   }

   init_require();

})();

Luckily enough, the "loader.js" and "Console.jsm" files are all under the same path in all Gecko applications I tried. And with a little more luck, they will stay there in future versions. ¬¬

I have been testing Custom Buttons add-on with this addition for several weeks now. Everything seems to work fine for now in all Gecko applications that I tried (latest versions of Firefox Stable/Developer Edition/Nightly, SeaMonkey, Palemoon and Thunderbird).

Some notes
  • I do not know if the contextBuilder.js file is the right place to "initialize" this function. I will leave this to the experts to decide.
  • The sdk/selection module it still not working with Electrolysis enabled. But it seems that they plan to fix it. Bug 1060695
  • Although I used it as an example, the sdk/notifications module has the same problem than the nsIAlertsService and the CB function custombuttons.alertSlide. The notification is never displayed on the first run. That's why I use a custom function that works consistently in all Gecko applications.
    Code: Select all
    function notifyme(aTitle, aMsg, aImg, aCallback) {
          let origin = (Services.prefs.getPrefType("ui.alertNotificationOrigin") !== 0) ?
             Services.prefs.getIntPref("ui.alertNotificationOrigin") :
             null;
          let win = Services.ww.openWindow(null, "chrome://global/content/alerts/alert.xul",
             "_blank", "chrome,titlebar=no,popup=yes", null);
          win.arguments = [aImg, aTitle, aMsg, !!aCallback, "", origin, "", "", null, (!!aCallback ? aCallback : null)];
       }
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby makondo » Sun Mar 13, 2016 6:08 pm

CB seems to be broken in the last nightly (as of yesterday): clicking Edit does nothing, the same stands for all Rclick menu items.
Stylish is broken too, see here.
It seems to be due to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1254752

Here are the errors i see, hope it helps:

1.png
1.png (38.04 KiB) Viewed 288 times
makondo
 
Posts: 1636
Joined: Sun Dec 25, 2011 7:17 pm

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby Odyseus » Mon Mar 14, 2016 1:25 am

Hello, g@ys.

makondo: Those "errors" that you see have nothing to do with CB being broken on Nightly. Those are warnings and they tell you that the getBrowserSelection is deprecated (will be removed in the future) and are triggered by one of your installed Custom Buttons (the one with ID 25 to be more precise).

Image
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

Re: [FIXED] CB broken on all Firefox versions higher than 43

Postby makondo » Mon Mar 14, 2016 2:10 am

Thanks! Unfortunately, i can't tell which button is 25. I have 60 of them but my AM says today:

1.png
1.png (114.94 KiB) Viewed 274 times


Image

I'm sure it's due to that patch that broke some exts. Hopefully Anton will update CB soon and everything will get back to norm again (for a day or two).
According to my saved html, it's the translator button by srazzano but he's out for a while. It's all right, the button works anyway for now but i'll keep it mind and remind him when he'll be available again. Thanks )i did update my CB with your version, it's working well).
makondo
 
Posts: 1636
Joined: Sun Dec 25, 2011 7:17 pm

Previous

Return to Bug report