MozillaZine

keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
morat
 
Posts: 4019
Joined: February 3rd, 2009, 6:29 pm

Post Posted September 18th, 2020, 1:25 pm

You can create keyboard shortcuts that execute custom commands with the tbkeys addon.

tbkeys
http://github.com/willsALMANJ/tbkeys
http://github.com/willsALMANJ/tbkeys/blob/master/addon/background.js

tbkeys custom command example
http://forums.mozillazine.org/viewtopic.php?p=14868330#p14868330

The tbkeys lite addon does not allow custom commands.

tbkeys lite
http://addons.thunderbird.net/thunderbird/addon/987885

P.S.

Here is how to add key bindings support for the message window to the tbkeys addon.

More info: viewtopic.php?p=14872137#p14872137
Last edited by morat on October 20th, 2020, 8:42 am, edited 2 times in total.

Oomingmak
 
Posts: 198
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted October 10th, 2020, 8:12 am

morat wrote:@Oomingmak

Try something like:

Code: Select all
(function () {
  var uri = gBrowser.contentDocument.documentURIObject.spec;
  // var uri = gBrowser.contentDocument.location.href;
  // var uri = gBrowser.contentWindow.location.href;
  // var uri = content.location.href;
  var win = OpenBrowserWindow();
  win.addEventListener("load", function () {
    win.setTimeout(function () {
      win.loadURI(uri);
      // win.gBrowser.loadURI(uri);
      // win.content.location.href = uri;
    }, 0);
  }, true);
})();

Similar thread: viewtopic.php?f=23&t=3028803

I appreciate your reply, morat.

Unfortunately I have been unable to make this work using the code as provided. I tried substituting the OpenBrowserWindow({remote: false}); code (from the thread that you linked) for the standard OpenBrowserWindow(); into the code sample you provided (I'm not sure if that was the correct thing to do), but nothing happens.

The OpenBrowserWindow({remote: false}); command works fine on its own (although it just opens a blank window) but my attempts to pass the active tab uri to the new window have all failed. Apologies, I'm really inexperienced with this kind of stuff.

Any pointers to where I might be going wrong?

morat
 
Posts: 4019
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 10th, 2020, 10:06 am

@Oomingmak

Are you running the code in a e10s enabled window in Waterfox 56? If so, then that is why the code fails.

TypeError: gBrowser.contentDocument is null

The following code works here in Firefox 81. It should also work in Firefox 52.

Code: Select all
(function () {
  var uri = "http://www.mozillazine.org/";
  var win = OpenBrowserWindow();
  win.addEventListener("load", function () {
    win.setTimeout(function () {
      win.alert(uri);
    }, 0);
  }, true);
})();

The following e10s compatible code works here in Firefox 81.

Code: Select all
(function () {
  var script = "data:text/plain," + encodeURIComponent(`
    var data = {};
    data.href = content.location.href;
    sendAsyncMessage("foobar", data);
  `);
  gBrowser.selectedBrowser.messageManager.addMessageListener("foobar", function removeMe(message) {
    gBrowser.selectedBrowser.messageManager.removeMessageListener("foobar", removeMe);
    var uri = message.data.href;
    var win = OpenBrowserWindow();
    win.addEventListener("load", function () {
      win.setTimeout(function () {
        win.alert(uri);
      }, 0);
    }, true);
  });
  gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
})();

The following code doesn't disable e10s in the new window in Firefox 81. I can check the multiprocess status in the about:support tab.

Code: Select all
OpenBrowserWindow({remote: false});

Firefox 52 Reference
http://dxr.mozilla.org/mozilla-esr52/search?q=function+OpenBrowserWindow&redirect=false
http://dxr.mozilla.org/mozilla-esr52/source/browser/config/version.txt

Waterfox 56 Reference
http://github.com/MrAlex94/Waterfox/blob/classic/browser/base/content/browser.js
http://github.com/MrAlex94/Waterfox/blob/classic/browser/config/version.txt

Oomingmak
 
Posts: 198
Joined: July 10th, 2004, 7:46 pm
Location: UK

Post Posted October 10th, 2020, 11:21 am

Thanks so much for your detailed reply.

Yes, I am running the code in an e10s enabled Waterfox window (hence the desire to find a hotkey to open a non-e10s window when necessary).

I seem to be getting closer to a working result.

Your latest code example opens a non-e10s window and correctly detects the current page uri to be loaded into the new non-e10s window. However, instead of loading the URI I instead get a javascript warning pop-up dialog that contains no message other than the URI of the page that is being passed to the non-e10s window. Meanwhile the non e10s window does open, but it always just defaults to my home page.

Image

The same thing happens with your first code example: a non-e10s window opens, but I get a javascript application warning saying: http://www.mozillazine.org/ (which is the URI stated in the first code example).

So, the correct page URI is now being forwarded (for whatever page is currently active at the time the code is run), but something is causing it to fall at last hurdle and the URI is not actually loaded.

morat
 
Posts: 4019
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 10th, 2020, 1:09 pm

@Oomingmak

Try this:

Code: Select all
(function () {
  var script = "data:text/plain," + encodeURIComponent(`
    var data = {};
    data.href = content.location.href;
    sendAsyncMessage("foobar", data);
  `);
  gBrowser.selectedBrowser.messageManager.addMessageListener("foobar", function removeMe(message) {
    gBrowser.selectedBrowser.messageManager.removeMessageListener("foobar", removeMe);
    var uri = message.data.href;
    var win = OpenBrowserWindow();
    win.addEventListener("load", function () {
      win.setTimeout(function () {
        win.gBrowser.loadURI(uri);
      }, 0);
    }, true);
  });
  gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false);
})();

P.S.

You need to provide the triggeringPrincipal property starting in Firefox 64.

Code: Select all
gBrowser.loadURI("http://www.mozillazine.org/", {
  triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 3 guests