Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

How do I set the general zoom level programmatically

  • 4 trả lời
  • 2 gặp vấn đề này
  • 394 lượt xem
  • Trả lời mới nhất được viết bởi cor-el

more options

When I use Firefox on the external monitor, I set the zoom level to 150%. When I leave home a take my laptop with me, I set the zoom level to 100% to use with a smaller screen.

I want to automate setting the zoom level.

Is there a way to programmatically set the zoom level from a script? Does Firefox expose such an API / command-line tool?

Thanks!

When I use Firefox on the external monitor, I set the zoom level to 150%. When I leave home a take my laptop with me, I set the zoom level to 100% to use with a smaller screen. I want to automate setting the zoom level. Is there a way to programmatically set the zoom level from a script? Does Firefox expose such an API / command-line tool? Thanks!

Giải pháp được chọn

Hi Pierre, this is a tough one. The default zoom level is stored in a database with site-specific zoom levels, and there's no preference you can set directly to modify that value.

You definitely can do it with a script you run manually in the Browser Console window, which has an optional global command line. The Options page is probably faster...

/* Default Zoom Level Setter for the Browser Console (2020-08-12)

   NOTE: BEFORE YOU CAN RUN THIS SCRIPT, ONE-TIME SETUP:
   Type or paste about:config into the address bar and press Enter
   Click the button promising to be careful
   In the search box type devt and pause while Firefox filters the list
   If devtools.chrome.enabled is false, double-click it to toggle to true

   Paste this entire script into the command line at the bottom of the Browser Console 
   (Windows/Linux: Ctrl+Shift+j; Mac: Command+Shift+j). Then press Enter to run it. 
   Firefox should flip to an open window and ask what percentage you want.
   
   Ref. https://searchfox.org/mozilla-release/source/browser/components/preferences/main.js#1166
*/

var newpct = window.prompt('New default zoom percentage (e.g., 100, 120, ...)?', '150');
if (newpct){
  let cps2 = Cc["@mozilla.org/content-pref/service;1"].getService(Ci.nsIContentPrefService2);
  let nonPrivateLoadContext = Cu.createLoadContext();
  let win = window.browsingContext.topChromeWindow;
  cps2.setGlobal(win.FullZoom.name, parseFloat((newpct / 100).toFixed(2)), nonPrivateLoadContext);
}
Đọc câu trả lời này trong ngữ cảnh 👍 1

Tất cả các câu trả lời (4)

more options

Giải pháp được chọn

Hi Pierre, this is a tough one. The default zoom level is stored in a database with site-specific zoom levels, and there's no preference you can set directly to modify that value.

You definitely can do it with a script you run manually in the Browser Console window, which has an optional global command line. The Options page is probably faster...

/* Default Zoom Level Setter for the Browser Console (2020-08-12)

   NOTE: BEFORE YOU CAN RUN THIS SCRIPT, ONE-TIME SETUP:
   Type or paste about:config into the address bar and press Enter
   Click the button promising to be careful
   In the search box type devt and pause while Firefox filters the list
   If devtools.chrome.enabled is false, double-click it to toggle to true

   Paste this entire script into the command line at the bottom of the Browser Console 
   (Windows/Linux: Ctrl+Shift+j; Mac: Command+Shift+j). Then press Enter to run it. 
   Firefox should flip to an open window and ask what percentage you want.
   
   Ref. https://searchfox.org/mozilla-release/source/browser/components/preferences/main.js#1166
*/

var newpct = window.prompt('New default zoom percentage (e.g., 100, 120, ...)?', '150');
if (newpct){
  let cps2 = Cc["@mozilla.org/content-pref/service;1"].getService(Ci.nsIContentPrefService2);
  let nonPrivateLoadContext = Cu.createLoadContext();
  let win = window.browsingContext.topChromeWindow;
  cps2.setGlobal(win.FullZoom.name, parseFloat((newpct / 100).toFixed(2)), nonPrivateLoadContext);
}
more options

@jscher2000 There is now a "Default zoom" option in Preferences->Zoom->Default zoom . I can't seem to find the about:config option to set it. Any ideas?

more options

rathann said

@jscher2000 There is now a "Default zoom" option in Preferences->Zoom->Default zoom . I can't seem to find the about:config option to set it. Any ideas?

It is not stored in about:config. It is stored in the content-prefs.sqlite database along with site-specific zoom levels (it is associated with a group with a null name).

(You can use this query in a SQLite viewer to list out the zoom levels in the database: SELECT name, value FROM 'prefs' left outer join 'groups' on prefs.groupID = groups.id WHERE settingID = 1 )

more options

You can consider two use separate profiles each with their own default zoom setting and use Sync to keep both profiles synchronized.