Hilfe durchsuchen

Vorsicht vor Support-Betrug: Wir fordern Sie niemals auf, eine Telefonnummer anzurufen, eine SMS an eine Telefonnummer zu senden oder persönliche Daten preiszugeben. Bitte melden Sie verdächtige Aktivitäten über die Funktion „Missbrauch melden“.

Learn More

How can I set default preferences in 56.0 via powershell?

  • 5 Antworten
  • 1 hat dieses Problem
  • 74 Aufrufe
  • Letzte Antwort von nburglin

more options

I need to set these preferences prior to opening the browser for the first time. We are auto-installing Firefox on a Windows AWS AMI, and then using Selenium to perform tests through Firefox, however need some preferences updated prior to actually opening up the GUI or it halts the tests. I need to disable things like the popup for the importing of bookmarks, options, etc... from other browsers.

Side-note, I've tried this article, however I just get an error that states "JavaScript error: mozilla.cfg, line 1: SyntaxError: illegal character"

   https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment 

Here is my entire mozilla.cfg file (it won't let me attach the file)

// Disable updater" > $ffConfigFile lockPref("app.update.enabled", false); // make absolutely sure it is really off lockPref("app.update.auto", false); lockPref("app.update.mode", 0); lockPref("app.update.service.enabled", false); // Disable default browser checks lockPref("browser.shell.checkDefaultBrowser", false);

I need to set these preferences prior to opening the browser for the first time. We are auto-installing Firefox on a Windows AWS AMI, and then using Selenium to perform tests through Firefox, however need some preferences updated prior to actually opening up the GUI or it halts the tests. I need to disable things like the popup for the importing of bookmarks, options, etc... from other browsers. Side-note, I've tried this article, however I just get an error that states "JavaScript error: mozilla.cfg, line 1: SyntaxError: illegal character" https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment Here is my entire mozilla.cfg file (it won't let me attach the file) // Disable updater" > $ffConfigFile lockPref("app.update.enabled", false); // make absolutely sure it is really off lockPref("app.update.auto", false); lockPref("app.update.mode", 0); lockPref("app.update.service.enabled", false); // Disable default browser checks lockPref("browser.shell.checkDefaultBrowser", false);

Ausgewählte Lösung

Unfortunately, that doesn't change the output. Firefox crashes before it starts up with that error that there is a syntax error at line one.

Playing with it some more, I was able to get past that error by putting everything on a single line. That indicated it was something weird with some sort of newline encoding.

I originally created this file using powershell here. If I do that, I get the configuration error again. So it's got to be something with the way the file gets formatted using powershell to append text to the file.

echo "Setting auto update to false for Firefox"

   New-Item "C:\Program Files\Mozilla Firefox\defaults\preferences" -ItemType directory
   $generalConfigFile = "C:\Program Files\Mozilla Firefox\defaults\pref\autoconfig.js"
   $ffConfigFile = "C:\Program Files\Mozilla Firefox\mozilla.cfg"
   "// Firefox Config" | Add-Content -Path $generalConfigFile
   'pref("general.config.filename", "mozilla.cfg");' | Add-Content -Path $generalConfigFile
   'pref("general.config.obscure_value", 0);' | Add-Content -Path $generalConfigFile
   "// Disable updater" > $ffConfigFile
   'lockPref("app.update.enabled", false);' >> $ffConfigFile
   "// make absolutely sure it is really off" >> $ffConfigFile
   'lockPref("app.update.auto", false);' >> $ffConfigFile
   'lockPref("app.update.mode", 0);' >> $ffConfigFile
   'lockPref("app.update.service.enabled", false);' >> $ffConfigFile
   "// Disable default browser check" >> $ffConfigFile
   'lockPref("browser.shell.checkDefaultBrowser", false);' >> $ffConfigFile


Now that I'm looking at it, I'm not sure why the mismatch from using the "Add-Content" for the generalConfigFile vs just the >> to the ffConfigFile.

I updated it all to use the "Add-Content" module and it works with no issues!

Diese Antwort im Kontext lesen 👍 0

Alle Antworten (5)

more options

The code you posted works fine, so there must be a problem with the formatting of the mozilla.cfg file.

Are you sure the mozilla.cfg file is a plain text file and not a RTF or otherwise formatted file?

You can open the file in a Firefox tab or in the Scratchpad.

more options

Hi cor-el

When I move away the mozilla.cfg and the autoconfig.js files away, I'm able to open Firefox. Then I can open the mozilla.cfg in a firefox tab with no issues. I double checked using Sublime text editor and it shows as Plain Text as well.

Here is what I have in defaults\pref\autoconfig.js

// Firefox Config pref("general.config.filename", "mozilla.cfg"); pref("general.config.obscure_value", 0);

more options

You can try to add a try and catch block and check the Browser Console for error messages.

// first line is a comment
try{
// Disable updater" > $ffConfigFile
lockPref("app.update.enabled", false);
// make absolutely sure it is really off
lockPref("app.update.auto", false);
lockPref("app.update.mode", 0);
lockPref("app.update.service.enabled", false);
// Disable default browser checks
lockPref("browser.shell.checkDefaultBrowser", false);
} catch(e){Components.utils.reportError(e);}
more options

Ausgewählte Lösung

Unfortunately, that doesn't change the output. Firefox crashes before it starts up with that error that there is a syntax error at line one.

Playing with it some more, I was able to get past that error by putting everything on a single line. That indicated it was something weird with some sort of newline encoding.

I originally created this file using powershell here. If I do that, I get the configuration error again. So it's got to be something with the way the file gets formatted using powershell to append text to the file.

echo "Setting auto update to false for Firefox"

   New-Item "C:\Program Files\Mozilla Firefox\defaults\preferences" -ItemType directory
   $generalConfigFile = "C:\Program Files\Mozilla Firefox\defaults\pref\autoconfig.js"
   $ffConfigFile = "C:\Program Files\Mozilla Firefox\mozilla.cfg"
   "// Firefox Config" | Add-Content -Path $generalConfigFile
   'pref("general.config.filename", "mozilla.cfg");' | Add-Content -Path $generalConfigFile
   'pref("general.config.obscure_value", 0);' | Add-Content -Path $generalConfigFile
   "// Disable updater" > $ffConfigFile
   'lockPref("app.update.enabled", false);' >> $ffConfigFile
   "// make absolutely sure it is really off" >> $ffConfigFile
   'lockPref("app.update.auto", false);' >> $ffConfigFile
   'lockPref("app.update.mode", 0);' >> $ffConfigFile
   'lockPref("app.update.service.enabled", false);' >> $ffConfigFile
   "// Disable default browser check" >> $ffConfigFile
   'lockPref("browser.shell.checkDefaultBrowser", false);' >> $ffConfigFile


Now that I'm looking at it, I'm not sure why the mismatch from using the "Add-Content" for the generalConfigFile vs just the >> to the ffConfigFile.

I updated it all to use the "Add-Content" module and it works with no issues!

Geändert am von nburglin

more options

Now that I'm looking at it, I'm not sure why the mismatch from using the "Add-Content" for the generalConfigFile vs just the >> to the ffConfigFile.

I updated it all to use the "Add-Content" module and it works with no issues. I appreciate the help though!