jguinch

Firefox configuration

4 posts in this topic

Hello !

Here is a small function which allows you to make changes in the Firefox configuration file (of the user running the script)

Warning : to make changes into the configuration file, Firefox must be stopped

Here you can find some settings in this webpage : http://kb.mozillazine.org/About:config_entries

 

Examples :

; Changes the start page
_FF_Config("browser.startup.homepage", "http://www.autoitscript.com/forum")

; Set a manual proxy
_FF_Config("network.proxy.type", 1) ; Sets the proxy in manual mode
_FF_Config("network.proxy.http", "192.168.1.10") ; Sets the http proxy name/IP
_FF_Config("network.proxy.http_port", 3128) ; Sets the http proxy port
_FF_Config("network. proxy. autoconfig_url") ; Remove the proxy url

; Allow popups
_FF_Config("dom.disable_open_during_load", false)

Also, you can use _FF_GetProfileList() to retrieve the list of Firefox profiles for the current user.

Now, the two functions :

#include <File.au3> ; needed for _PathFull

; #FUNCTION# ====================================================================================================================
; Name ..........: _FF_Config
; Description ...: Configures Mozilla Firefox
; Syntax ........: _FF_Config($sSettingName[, $sSettingValue = Null[, $sProfileName = ""]])
; Parameters ....: $sSettingName        - Name of the setting to add, change or delete.
;                  $sSettingValue       - [optional] Value of the setting. Default is Null = deletes the line.
;                  $sProfileName        - [optional] Name of the Firefox profile. Default is "" = all Firefox profiles
; Return values .: Success              - Returns 1
;                  Failure              - Returns 0 and set @error to :
;                                          1 : Unable to list the Firefox profiles
;                                          2 : Unable to load the specified Firefox profile
;                                          3 : Firefox is running
; Author ........: jguinch
; ===============================================================================================================================
Func _FF_Config($sSettingName, $sSettingValue = Null, $sProfileName = "")
    Local $sFFConfigFile = "prefs.js"
    Local $sContent, $aProfiles = _FF_GetProfileList(), $iError = 0, $hPrefs
    If @error Then Return SetError(@error, 0, 0)

    If ProcessExists("firefox.exe") Then Return SetError(3, 0, 0)

    If IsString($sSettingValue) Then $sSettingValue = '"' & $sSettingValue & '"'
    If IsBool($sSettingValue) Then $sSettingValue = StringLower($sSettingValue)

    For $i = 1 To $aProfiles[0][0]
        If $sProfileName <> "" AND $aProfiles[$i][0] <> $sProfileName Then ContinueLoop
        $sContent = FileRead($aProfiles[$i][1] & "\" & $sFFConfigFile)
        If @error Then Return SetError(2, 0, 0)

        If $sSettingValue = Null Then
            $sNewContent = StringRegExpReplace($sContent, '(?mi)^\Quser_pref("' & $sSettingName & '"\E\V+\R', '')
        Else
            $sNewContent = StringRegExpReplace($sContent, '(?mi)^\Quser_pref("' & $sSettingName & '", \E\K.+(?=\);$)', $sSettingValue)
            If NOT @extended Then $sNewContent = StringRegExpReplace($sContent, ";\K\v*$", @CRLF & 'user_pref("' & $sSettingName & '", ' & $sSettingValue & ');' & @CRLF)
        EndIf

        $hPrefs = FileOpen($aProfiles[$i][1] & "\" & $sFFConfigFile, 2)
        If $hPrefs = -1 Then Return SetError(2, 0, 0)
        FileWrite($hPrefs, $sNewContent)
        FileClose($hPrefs)
    Next

    Return 1
EndFunc



; #FUNCTION# ====================================================================================================================
; Name ..........: _FF_GetProfileList
; Description ...: List the Firefox profiles in a 2D array
; Syntax ........: _FF_GetProfileList()
; Parameters ....: None
; Return values .: Success              - Returns a 2D array (see remarks)
;                  Failure              - Returns 0 and set @error to 1 (unable to list the Firefox profiles)
; Author ........: jguinch
; Remarks........: The array returned is two-dimensional and is made up as follows:
;                    $aArray[0][0] : Number of profiles
;                    $aArray[0][1] : Default profile index in the array
;                    $aArray[1][0] : 1st profile name
;                    $aArray[1][1] : 1st profile path
;                    ...
;                    $aArray[n][0] : nth profile name
;                    $aArray[n][1] : nth profile path
; ===============================================================================================================================
Func _FF_GetProfileList()
    Local $sProfileName, $sIsRelative, $sProfilePath, $aResult[10][2] = [[0]]
    Local $sFFAppDataPah = @AppDataDir & "\Mozilla\Firefox"
    Local $sProfiles = $sFFAppDataPah & "\profiles.ini"
    Local $aSections = IniReadSectionNames($sProfiles)
    If @error OR NOT IsArray($aSections) Then Return SetError(1, 1, 0)

    For $i = 1 To $aSections[0]
        If $aSections[$i] <> "General" Then
            $sProfileName = IniRead($sProfiles, $aSections[$i], "Name", "")
            $sIsRelative = IniRead($sProfiles, $aSections[$i], "IsRelative", "")
            $sProfilePath = IniRead($sProfiles, $aSections[$i], "Path", "")

            If $sIsRelative = "" OR $sProfilePath = "" OR $sProfileName = "" Then ContinueLoop
            If Number($sIsRelative) = 1 Then $sProfilePath = _PathFull( @AppDataDir & "\Mozilla\Firefox\" & StringReplace($sProfilePath, "/", "\") )
            If NOT FileExists($sProfilePath & "\prefs.js") Then ContinueLoop

            $aResult[0][0] += 1
            If $aResult[0][0] = UBound($aResult) Then Redim $aResult[ UBound($aResult) * 2][2]

            If Number(IniRead($sProfiles, $aSections[$i], "Default", "error")) = 1 Then $aResult[0][1] = $aResult[0][0]

            $aResult[ $aResult[0][0] ][0] = $sProfileName
            $aResult[ $aResult[0][0] ][1] = $sProfilePath
        EndIf
    Next

    If NOT $aResult[0][1] AND $aResult[0][0] > 0 Then $aResult[0][1] = 1
    Redim $aResult [ $aResult[0][0] + 1 ][2]

    Return $aResult
EndFunc
4 people like this

Share this post


Link to post
Share on other sites



hi

very good sample but add sample proxy list change.

 

Share this post


Link to post
Share on other sites

@jguinch

Thanks,

 

Look here:

https://java.com/en/download/help/firefox_java.xml

_FF_Config('dom.ipc.plugins.java.enabled',False)

mLipok

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • rte7
      By rte7
      Hello. We work with the BMC Remedy site to manage incidents and would like to automate the processes of clicking through this button code:
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a> I use firefox with mozrepl and autoit with include FF.au3
      I need your help
      I read the topic https://www.autoitscript.com/forum/topic/95595-ffau3-v0601b-10/ but I could not run the code from the listed commands
      ...
      It is necessary to press the button and from the list of the menu of cahorsations to select the item = "zone of trust abonent"
      Screen # 1 http://joxi.ru/52aJK7bh4a7ypA or below.
      1) Press button
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a>
      2) After pressing the button, I need to choose in this menu of 4 items to select an item called "zone of trust abonent", Screen # 2 - http://joxi.ru/p27gwQKHo71VQ2
      html code table items
      <table class="MenuTable" cellpadding="0" cellspacing="0" style="width: 179px;"> <tbody class="MenuTableBody"> <tr class="MenuTableRow"> <td class="MenuEntryName" nowrap="">zone of trust abonent</td> <td class="MenuEntryNoSub" arvalue="zone of trust abonent"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust operator"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust third operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust third operator"></td></tr> <tr class="MenuTableRow"><td class="MenuEntryNameHover" nowrap="">No settings</td> <td class="MenuEntryNoSubHover" arvalue="No settings"></td> </tr> </tbody> </table>
       
       
      More in detail, I choose from the menu item "zone of trust abonent" Screen # 3 - http://joxi.ru/GrqVq4ZIQEPW4m

       
      3) The choice is made, Screen # 4 http://joxi.ru/v297w6aC3PovLr
      <textarea class="text sr " wrap="off" id="arid_WIN_0_1000002488" cols="20" maxlen="60" style="top:21; left:0; width:179; height:21;" armenu="CFG:PRC:CategoryHPD-Res-T1-Q" mstyle="2" arautoc="1" arautocmb="1" arautocak="0" arautoctt="400" rows="1"> </textarea>
       
      It's all. I would be very grateful to you =) !!!!!!!!!!
      Here are more detailed codes in the attachment. 
      button1.txt
      menu - table.txt
      all.txt
    • milos83
      By milos83
      How can I check if element is focused in Firefox using FF.au3 UDF?
      This is my try:
      I have prepared a function that checks if the object is focused:
       
      _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully.
      After a lot of try/fails I inserted an alert box in order to display the object being compared.
      Here is what I got
       
      The focused object is: [object XULElement]
      The object that I send for comparing is [object HTMLInputElement]
      Why is that?
       
       
    • spuuunit
      By spuuunit
      Is it possible to know if a textbox is active in FireFox?
       
      This is what I want:
      if (Textbox in FireFox == Active) { }
    • tonycst
      By tonycst
      I want to pass "about:config" to firefox
      If i do ShellExecute ("firefox.exe","about:config"), i get new instance of firefox opening up which is bad because it makes changes to another profile instead of one that is currently running.
      Any ideas ?
    • mazz3d
      By mazz3d
      hello  everyone,
      I'm new with AutoIT and just looking for a way to open Firefox with random window size
      i have tried too many different samples from the web, some how it works but i can't make it works with Firefox 
      MozRpel and ff.au3 installed 
      right now i can open Firefox with this code, but i still can't control the window of Firefox
      ; open firefox #include <ff.au3> _FFStart() ; open firefox with random size