0

I am using Firefox Scratchpad to understand the scaling behavior that results when the user types the CTRL-PLUS and CTRL-MINUS keys. In Javascript Scratchpad, I'm evaluating a snippet of Javascript code that accesses the Components.interfaces.nsIDOMWindowUtils.screenPixelsPerCSSPixel property like this:

var util = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils); 
util.screenPixelsPerCSSPixel

In Scratchpad typing CTRL-L after the last l in screenPixelsPerCSSPixel above results in an Exception:

Exception: The operation is insecure.

(Note that the current active Firefox tab is pointing to http://www.google.com).

The devtools.chrome.enabled flag is set to true in this context, but that does not seem to matter as an Exception is still being thrown.

What do I need to do in order to get Javascript Scratchpad to display that value?

This is intended only to be temporary to gain understanding during a debug ritual. Set aside for now the obvious question of "Why is it a security risk to show a scaling factor?". I'm only after getting at the value from the confines of standard, and safe, Firefox controls such as enabling/disabling about:config values that I can easily undo later when I'm done.

bgoodr
  • 2,744
  • 1
  • 30
  • 51

1 Answers1

0

Here is the answer I found:

Accessing the window variable from the Scratchpad scope whose Environment (see its Environment menu) is set to Content yeilds one type of object, while if Environment was set to Browser, a different type of object is in play (CTRL-L on it in Scratch pad reports it is of type ChromeWindow). The window.content object is the content object relative to the ChromeWindow object.

The value of

....QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils).screenPixelsPerCSSPixel

relative to the window object (ChromeWindow) object returns 1, while calling it on the window.content shows something other than 1 and show that scaling is involved.

(EDIT: I relocated the Javascript code that used to be here; see below.)

To demonstrate using the value, I've provided some sample Javascript in an answer to my other question at Finding top-level X Window x/y coordinates of CTRL-F text in Firefox

Community
  • 1
  • 1
bgoodr
  • 2,744
  • 1
  • 30
  • 51