搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

Using Mozilla.cfg to focus a custom new tab page

  • 1 回覆
  • 1 有這個問題
  • 158 次檢視
  • 最近回覆由 Vallode

more options

Hi everyone,

I am having trouble getting my custom new tab page to be focused when opened (instead of the address bar).

I am currently using the `autoconfig.js` + `mozilla.cfg` approach to overriding the `AboutNewTab.jsm` service with a custom local file. This is working great with the two files containing this code:

autoconfig.js: ``` pref("general.config.filename", "mozilla.cfg"); pref("general.config.obscure_value", 0); ```

mozilla.cfg: ``` // Custom firefox config

let { classes:Cc, interfaces:Ci, utils:Cu } = Components;

try {

 Cu.import("resource:///modules/AboutNewTab.jsm");
 let newTabURL = "file:///home/vallode/Documents/test/index.html";
 AboutNewTab.newTabURL = newTabURL;

} catch(e) { Cu.reportError(e); } ```

I have been attempting to use the `gBrowser` global to add an event listener to the new tab opening, but with no success. Could anyone point me in the right direction for something like this?

Hi everyone, I am having trouble getting my custom new tab page to be focused when opened (instead of the address bar). I am currently using the `autoconfig.js` + `mozilla.cfg` approach to overriding the `AboutNewTab.jsm` service with a custom local file. This is working great with the two files containing this code: autoconfig.js: ``` pref("general.config.filename", "mozilla.cfg"); pref("general.config.obscure_value", 0); ``` mozilla.cfg: ``` // Custom firefox config let { classes:Cc, interfaces:Ci, utils:Cu } = Components; try { Cu.import("resource:///modules/AboutNewTab.jsm"); let newTabURL = "file:///home/vallode/Documents/test/index.html"; AboutNewTab.newTabURL = newTabURL; } catch(e) { Cu.reportError(e); } ``` I have been attempting to use the `gBrowser` global to add an event listener to the new tab opening, but with no success. Could anyone point me in the right direction for something like this?

被選擇的解決方法

I've had good success using the following defined in my mozilla.cfg

   // Auto focus new tab content
   try {
     Cu.import("resource://gre/modules/Services.jsm");
     Cu.import("resource:///modules/BrowserWindowTracker.jsm");
   
     Services.obs.addObserver((event) => {
       window = BrowserWindowTracker.getTopWindow();
       window.gBrowser.selectedBrowser.focus();
     }, "browser-open-newtab-start");
   } catch(e) { Cu.reportError(e); }
從原來的回覆中察看解決方案 👍 0

所有回覆 (1)

more options

選擇的解決方法

I've had good success using the following defined in my mozilla.cfg

   // Auto focus new tab content
   try {
     Cu.import("resource://gre/modules/Services.jsm");
     Cu.import("resource:///modules/BrowserWindowTracker.jsm");
   
     Services.obs.addObserver((event) => {
       window = BrowserWindowTracker.getTopWindow();
       window.gBrowser.selectedBrowser.focus();
     }, "browser-open-newtab-start");
   } catch(e) { Cu.reportError(e); }