It's because you have open the file in Read mode.
Here is your version, with some changes to work :
Func ChangeFFUseragent()
Local Const $sPrefPath = "C:\Users\Jerome\AppData\Roaming\Mozilla\Firefox\Profiles\er6wwvjm.default\prefs.js"
if FileExists($sPrefPath) Then
; If file not exists, exit
; Open the file for writing (append to the end of a file) and store the handle to a variable.
Local $hFileOpen = FileOpen($sPrefPath, 1)
If $hFileOpen = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
EndIf
; Read the contents of the file using the handle returned by FileOpen.
Local $sFileRead = FileRead($hFileOpen)
;Write new Useragent
FileWriteLine($hFileOpen, "user_pref(""general.useragent.override"", ""Some string"");" & @CRLF)
Else
MsgBox(4096,"Error", " Error finding Pref.js error:" & @error)
Exit
EndIf
EndFunc
Now, if you call the ChangeFFUseragent several times, a line will be added each time. It's cleaner to add the line only if needed and the replace it if already exists.
Try with this shortest code (there are two func parameters : profileDir and UserAgent string.
Global $FFProfile = @UserProfileDir & "\Application Data\Mozilla\Firefox\Profiles\autoitbrowser.default"
ChangeFFUseragent($FFProfile, "MyNewSuperUserAgentddd")
Func ChangeFFUseragent($sPrefPath, $sUserAgent)
If ProcessExists("firefox.exe") Then Return SetError(2, 0, 0)
Local $sFileRead = FileRead($sPrefPath & "\prefs.js")
If @error Then Return SetError(1, 0, 0)
$sFileRead = StringRegExpReplace($sFileRead, '(?i)("general\.useragent\.override", ?")([^"]+)', "$1" & $sUserAgent)
If NOT @extended Then $sFileRead &= @CRLF & 'user_pref("general.useragent.override", "' & $sUserAgent & '");'
$hFile = FileOpen($sPrefPath & "\prefs.js", 2)
If $hFile = -1 Then Return SetError(1, 0, 0)
FileWrite($hFile, $sFileRead)
FileClose($hFile)
Return 1
EndFunc