Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Przeszukaj pomoc

Unikaj oszustw związanych z pomocą.Nigdy nie będziemy prosić Cię o dzwonienie na numer telefonu, wysyłanie SMS-ów ani o udostępnianie danych osobowych. Zgłoś podejrzaną aktywność, korzystając z opcji „Zgłoś nadużycie”.

Learn More

[Update] Allow web page to override a keyboard shortcut

  • 3 odpowiedzi
  • 0 osób ma ten problem
  • 1 wyświetlenie
  • Ostatnia odpowiedź od jonschz

more options

The excellent answer here no longer works in Firefox 117.0 on MacOS. Unfortunately, that post is archived, so I cannot post an updated solution there. I would greatly appreciate if a moderator could add this post in the linked article, or at least link from there over to here.

For Firefox 117, the code needs to be modified slightly (two lines at the top need to be removed): ```

  //
  function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
  ConfigJS.prototype = {
   observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); },
   handleEvent: function (aEvent) {
     let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
     if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
       if (window._gBrowser) {
         let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"];
         for (var i=0; i < keys.length; i++) {
            let keyCommand = window.document.getElementById(keys[i]);
            if (keyCommand != undefined) { 
               keyCommand.removeAttribute("command"); 
               keyCommand.removeAttribute("key"); 
               keyCommand.removeAttribute("modifiers"); 
               keyCommand.removeAttribute("oncommand"); 
               keyCommand.removeAttribute("data-l10n-id"); 
            }
         }
       }
     }
   }
  };
  if (!Services.appinfo.inSafeMode) { new ConfigJS(); }

```

The excellent answer [[How to allow web page to override a keyboard shortcut|here]] no longer works in Firefox 117.0 on MacOS. Unfortunately, that post is archived, so I cannot post an updated solution there. I would greatly appreciate if a moderator could add this post in the linked article, or at least link from there over to here. For Firefox 117, the code needs to be modified slightly (two lines at the top need to be removed): ``` // function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); } ConfigJS.prototype = { observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); }, handleEvent: function (aEvent) { let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location; if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) { if (window._gBrowser) { let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"]; for (var i=0; i < keys.length; i++) { let keyCommand = window.document.getElementById(keys[i]); if (keyCommand != undefined) { keyCommand.removeAttribute("command"); keyCommand.removeAttribute("key"); keyCommand.removeAttribute("modifiers"); keyCommand.removeAttribute("oncommand"); keyCommand.removeAttribute("data-l10n-id"); } } } } } }; if (!Services.appinfo.inSafeMode) { new ConfigJS(); } ```

Wybrane rozwiązanie

That is this question:

You need to remove/replace this line as Services.jsm is no longer supported.

const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');

Use this instead:

const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;

Przeczytaj tę odpowiedź w całym kontekście 👍 1

Wszystkie odpowiedzi (3)

more options

Hi

To help us understand this better, please can you share a link to the archived question that you had found.

more options

Wybrane rozwiązanie

That is this question:

You need to remove/replace this line as Services.jsm is no longer supported.

const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');

Use this instead:

const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;

more options

Thank you! I indeed forgot to link the question, my bad. In my case I did not have to add your corrected line, removing it entirely worked out. I suspect there are other cases where it is needed.