3

I am using Firefox 23.0.1. I want to totally disable printing from Firefox, is this possible?

I used about:config to set the following properties:

  • print.always_print_silent = true
  • print.show_print_progress = false

It gets me half the way there, Firefox prints silently and does not show any indications of printing. However the job is still sent to the default printer.

I then tried to set print_printer to an empty string since this seems to be the default printer, but it sill sends the job to that printer.

Is there any way to completely disable printing for Firefox, preferably through the settings in about:config?

I want to do this since I have automatic semi-load tests (using Selenium together with JMeter). In the application that is tested, a pdf is embedded which has a javascript sending the pdf to the default printer. If printing cannot be disabled, a lot of garbage jobs would be sent to the printer.

Dave
  • 25,297
  • 10
  • 57
  • 69
Magnilex
  • 135
  • 1
  • 8
  • 1
    Well, can't you just not print? Or change the default printer? I think it may be useful if we know why you want this behaviour? – Dave Sep 11 '13 at 10:04
  • 1
    Please *always* include your OS. Solutions very often are dependent on the Operating System being used. Are you using Windows, Linux, Unix, OSX, BSD? Which version? – terdon Sep 11 '13 at 10:09
  • @terdon Sorry about that. First post at SU. – Magnilex Sep 11 '13 at 10:20
  • @DaveRook I will update my question with why I want this behaviour. – Magnilex Sep 11 '13 at 10:20
  • @DaveRook Changing the default printer would work, but to what? I don't really want to clutter the file system either. – Magnilex Sep 11 '13 at 10:25
  • More generalised question: [Looking for a 'fake' printer driver for Windows?](http://superuser.com/questions/216099/looking-for-a-fake-printer-driver-for-windows) (might be a candidate for a duplicate, actually). – Bob Sep 11 '13 at 10:39
  • @Bob Don't see how it could be a dup. I don't want all persons (developers) running the test to have to create a fake printer. If it was possible to disable printing from Firefox by some property (seems it is, see answer below), I could do this directly in the tests. – Magnilex Sep 11 '13 at 11:30

2 Answers2

6

You can disable the JavaScript print function to prevent JS-initiated print actions.

There are two ways to disable a JS function:

  • Set policies to disallow the function

  • Replace it with a dummy function

  • Another option is to set a dummy systemwide printer


Option 1: Security Policies

You can set the Configurable Security Policies by adding the following line to the user.js file (note: Firefox must be fully closed before this file can be modified):

user_pref("capability.policy.default.Window.print", "noAccess");

Alternatively, you could navigate to about:config and add a new string key with the same name and values. Do note that you will not be able to see or remove this key from within the config UI.

If you wish to only block this on specific sites, the following should work (replace the example domains):

user_pref("capability.policy.blockPrinting.Window.print", "noAccess");
user_pref("capability.policy.blockPrinting.sites", "http://example.com http://something.example.com");

The problem with this approach is that it will throw a JS exception, which may interfere with JS execution. The othe rapproach, a dummy JS function, is probably safer.


Option 2: Dummy Function

You can replace the print function with a dummy JS function like so:

window.print = function(){};

Any calls to window.print after this will do nothing. You can execute this on the required page by, e.g., a (Greasemonkey) userscript.


Option 3: Dummy Printer

The third option is to do as you have already done and disable the dialog, and then set the system default printer to one that does nothing. This is not recommended, since it will affect the whole system (though in most other programs you can simply select a different printer, it is inconvenient).

This question addresses creating a dummy printer in Windows.

Bob
  • 60,938
  • 25
  • 191
  • 216
  • Great answer, thanks! Option 1 in particular serves my needs. This way I can block printing from inside of the test classes, meaning not every person running the tests need to set up a dummy printer. – Magnilex Sep 11 '13 at 11:27
  • Option #1 did not work to prevent `window.print()` dialog for me after several attempts in "about:config" and user.js on Mac OS X. – thadk Jul 29 '16 at 18:16
  • @thadk I believe CSPs were removed at some point. Your best bet is overriding it with a userscript. – Bob Sep 07 '17 at 08:16
1

I don't see what this now has to do with Firefox. This is more about the print job.

You can install something a PDF writer as your printer and set it as default... However, you will probably be prompted to create save file names etc which may/may not be desirable.

You may be able to create a 'fake' printer (just install the drivers and software, set it as default so the print job never goes).

Turn the printer off during testing (and remember to clear the queue before turning it back on (this gets my vote but not sure of your exact situation).

There is possibly some 'virtual printer' software already in existence which may suffice for your needs (but recommending any is off topic here so please don't think I'm being unhelpful).

Dave
  • 25,297
  • 10
  • 57
  • 69