Jump to content

Firefox automated clean install, and config using mozilla.cfg


Recommended Posts

All,

I have decided to release my code for the automated clean install, set up and configuration of Mozilla Firefox with a Mozilla.cfg file included in my example as well. I seen an older version of this and decided to post mine on here. This is Windows 10 friendly.

The whole process once compiled executes in about 15 seconds on my machine from start to finish as it is extremely fast.

If you want to include your own Mozilla.cfg into the mix simply place Your Mozilla.cfg file in the same directory as the exe when it is run. If you do not wish to embed the Mozilla.cfg file into the script as a back up in case you forget you need to remove that line of code to embed it.

I hope this helps some people esp those wanting to understand how to use a cfg file to set default settings for all users without having to do it by putting all those files and folders in the defaultapp data folders.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Clear-App-firefox.ico
#AutoIt3Wrapper_Outfile=FirefoxUpdater(x64Stable)_x.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=Preformes a clean install of Firefox 64bit Stable version. Auto downloads latest version.
#AutoIt3Wrapper_Res_Description=Updates to the Latest 64bit Stable
#AutoIt3Wrapper_Res_Fileversion=2.5.0.0
#AutoIt3Wrapper_Res_ProductVersion=2.5.0.0
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <InetConstants.au3>
#include <EventLog.au3>
#include <Inet.au3>
#include <File.au3>
#include <array.au3>
#include <Misc.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants.

If UBound(ProcessList(@ScriptName)) > 2 Then Exit

TraySetToolTip("Firefox Updater")
HotKeySet("^!m", "MyExit") ; ctrl+Alt+m kills program ( hotkey )
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "About")
TrayCreateItem("") ; Create a separator line.
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "ExitScript")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button.
TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

Local $sVersion, $CVersion, $ecode

;https://www.mozilla.org/en-US/firefox/developer/all/
;https://www.mozilla.org/en-US/firefox/all/#
;https://www.mozilla.org/en-US/firefox/all/#en-US
;https://www.mozilla.org/en-US/firefox/beta/all/#en-US
;https://archive.mozilla.org/pub/firefox/candidates/48.0b1-candidates/build2/
;https://archive.mozilla.org/pub/firefox/candidates/

getfiles()
compare()
killapps()
uninstall()
dlinstall()
Exit

Func killapps()
    ; kill firefox and plugin if running
    If FileExists("C:\Program Files\Mozilla Firefox\") Then
        $cmd = "taskkill.exe /im firefox.exe /f /t"
        RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
        Sleep(300)
        $cmd = "taskkill.exe /im plugin* /f /t"
        RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
        Sleep(300)
        Call("remcfg64")
    EndIf

    If FileExists("C:\Program Files (x86)\Mozilla Firefox\") Then
        $cmd = "taskkill.exe /im firefox.exe /f /t"
        RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
        Sleep(300)
        $cmd = "taskkill.exe /im plugin* /f /t"
        RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
        Sleep(300)
        Call("remcfg32")
    EndIf
EndFunc   ;==>killapps


Func remcfg64()
    ; delete existing config file if exist
    $SSlist = _FileListToArrayRec("C:\Program Files\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $i = 1 To UBound($SSlist) - 1
        If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then
            FileDelete($SSlist[$i])
        ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then
            FileDelete($SSlist[$i])
        ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then
            FileDelete($SSlist[$i])
        EndIf
    Next
EndFunc   ;==>remcfg64

Func remcfg32()
    $SSlist = _FileListToArrayRec("C:\Program Files (x86)\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $i = 1 To UBound($SSlist) - 1
        If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then
            FileDelete($SSlist[$i])
        ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then
            FileDelete($SSlist[$i])
        ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then
            FileDelete($SSlist[$i])
        EndIf
    Next
EndFunc   ;==>remcfg32

Func uninstall()
    ; uninstall existing Firefox
    If FileExists("C:\Program Files\Mozilla Firefox\Firefox.exe") Then
        ShellExecuteWait("helper.exe", " /S", "C:\Program Files\Mozilla Firefox\uninstall")
    EndIf

    If FileExists("C:\Program Files (x86)\Mozilla Firefox\Firefox.exe") Then
        ShellExecuteWait("helper.exe", " /S", "C:\Program Files (x86)\Mozilla Firefox\uninstall")
    EndIf

    Sleep(1500)
    DirRemove("C:\Program Files (x86)\Mozilla Firefox\", 1)
    DirRemove("C:\Program Files\Mozilla Firefox\", 1)
EndFunc   ;==>uninstall

Func getfiles()
    ; get latest download
    Local $sTxt, $sTxt1
    $xjs = "C:\windows\temp\xjs.tmp"
    $xjs1 = "C:\windows\temp\xjs1.tmp"
    ;$sSite = "https://www.mozilla.org/en-US/firefox/beta/all/"
    $sSite = "https://www.mozilla.org/en-US/firefox/all/"
    ;$sNotes = "https://www.mozilla.org/en-US/firefox/beta/notes/"
    $sNotes = "https://www.mozilla.org/en-US/firefox/notes/"
    SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10)
    ControlSetText("Progress", "", "Static1", "Initializing", 2)
    $source = _INetGetSource($sSite)
    $sTxt = StringSplit($source, @LF)

    $q = 0
    $i = 0
    For $i = 1 To UBound($sTxt) - 1 ; is like saying read the line number
        ;GUIGetMsg();prevent high cpu usage
        If StringInStr($sTxt[$i], "=win64&amp;lang=en-US") > 1 Then
            $sActiveX1 = StringSplit($sTxt[$i], 'href="', 1)
            $sActiveX2 = StringSplit($sActiveX1[2], '"')
            Global $dia = $sActiveX2[1]
            $q = 1
        EndIf

        If UBound($sTxt) - 1 = $i Then
            $ecode = '404'
            EventLog()
            Exit
        EndIf


        If $q = 1 Then
            ExitLoop
        EndIf
    Next

    ; FIND VERSION
    $source = _INetGetSource($sNotes)
    $sTxt1 = StringSplit($source, @LF)

    $q = 0
    $i = 0
    For $i = 1 To UBound($sTxt1) - 1 ; is like saying read the line number
        ;GUIGetMsg();prevent high cpu usage
        If StringInStr($sTxt1[$i], "<title>Firefox") > 1 Then
            $sActiveX1 = StringSplit($sTxt1[$i], '<title>Firefox', 1)
            $sActiveX2 = StringSplit($sActiveX1[2], ',')
            $sVersion = StringStripWS($sActiveX2[1], 3)
            $q = 1
        EndIf
        If $sVersion = "" Then ; error correcting if mozilla changes page where version notes are located.
            $sVersion = "Current Version"
        EndIf
        If $q = 1 Then
            ExitLoop
        EndIf
    Next
    SplashOff()
EndFunc   ;==>getfiles


Func dlinstall()
    ; download and install
    $Version = $sVersion & " - 64 bit"
    _webDownloader($dia, "FFInstall.exe", $Version)

    SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10)
    ControlSetText("Progress", "", "Static1", "Installing Version " & $sVersion, 2)
    ShellExecuteWait("FFInstall.exe", " -ms", "C:\Windows\Temp\")

    If FileExists(@ScriptDir & "\mozilla.cfg") Then
        FileCopy(@ScriptDir & "\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1)
    Else
        FileInstall("G:\Users\username\Documents\Project\FirefoxDefault\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1)
    EndIf

    FileWrite("C:\Program Files\Mozilla Firefox\defaults\pref\local-settings.js", 'pref("general.config.obscure_value", 0);' & @CRLF & 'pref("general.config.filename", "mozilla.cfg");' & @CRLF)
    FileWrite("C:\Program Files\Mozilla Firefox\browser\override.ini", '[XRE]' & @CRLF & 'EnableProfileMigrator=false' & @CRLF)
    FileDelete("C:\windows\temp\" & "\FFInstall.exe")
    $CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION)
    SplashOff()
EndFunc   ;==>dlinstall

Func _webDownloader($sSourceURL, $sTargetName, $sVisibleName, $sTargetDir = "C:\windows\temp", $bProgressOff = True, $iEndMsgTime = 2000, $sDownloaderTitle = "Mozilla Firefox")
    ; Declare some general vars
    Local $iMBbytes = 1048576

    ; If the target directory doesn't exist -> create the dir
    If Not FileExists($sTargetDir) Then DirCreate($sTargetDir)

    ; Get download and target info
    Local $sTargetPath = $sTargetDir & "\" & $sTargetName
    Local $iFileSize = InetGetSize($sSourceURL)
    Local $hFileDownload = InetGet($sSourceURL, $sTargetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND)

    ; Show progress UI
    ProgressOn($sDownloaderTitle, "" & $sVisibleName)
    GUISetFont(8, 400)
    ; Keep checking until download completed
    Do
        Sleep(250)

        ; Set vars
        Local $iDLPercentage = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) * 100 / $iFileSize, 0)
        Local $iDLBytes = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) / $iMBbytes, 2)
        Local $iDLTotalBytes = Round($iFileSize / $iMBbytes, 2)

        ; Update progress UI
        If IsNumber($iDLBytes) And $iDLBytes >= 0 Then
            ProgressSet($iDLPercentage, $iDLPercentage & "% - Downloaded " & $iDLBytes & " MB of " & $iDLTotalBytes & " MB")
        Else
            ProgressSet(0, "Downloading '" & $sVisibleName & "'")
        EndIf
    Until InetGetInfo($hFileDownload, $INET_DOWNLOADCOMPLETE)

    ; If the download was successfull, return the target location
    If InetGetInfo($hFileDownload, $INET_DOWNLOADSUCCESS) Then
        ProgressSet(100, "Downloading '" & $sVisibleName & "' completed")
        If $bProgressOff Then
            Sleep($iEndMsgTime)
            ProgressOff()
        EndIf
        Return $sTargetPath
        ; If the download failed, set @error and return False
    Else
        Local $errorCode = InetGetInfo($hFileDownload, $INET_DOWNLOADERROR)
        ProgressSet(0, "Downloading '" & $sVisibleName & "' failed." & @CRLF & "Error code: " & $errorCode)
        If $bProgressOff Then
            Sleep($iEndMsgTime)
            ProgressOff()
        EndIf
        SetError(1, $errorCode, False)
        FileDelete("C:\windows\temp\" & "\FFInstall.exe")
        SplashOff()
    EndIf
EndFunc   ;==>_webDownloader

Func compare()
    $CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION)
    If $sVersion = $CVersion Then
        $ecode = '411'
        MsgBox(64, "Firefox says:", 'You have the latest version ' & $CVersion , 5)
        EventLog()
        Exit
    EndIf
EndFunc   ;==>compare


Func EventLog()

    If $ecode = '404' Then
        Local $hEventLog, $aData[4] = [0, 4, 0, 4]
        $hEventLog = _EventLog__Open("", "Application")
        _EventLog__Report($hEventLog, 1, 0, 404, @UserName, @UserName & ' No "exe" found for Mozilla Firefox. The webpage and/or download link might have changed. ' & @CRLF, $aData)
        _EventLog__Close($hEventLog)
    EndIf

    If $ecode = '411' Then
        Local $hEventLog, $aData[4] = [0, 4, 1, 1]
        $hEventLog = _EventLog__Open("", "Application")
        _EventLog__Report($hEventLog, 0, 0, 411, @UserName, @UserName & " Mozilla Firefox " & "version " & $CVersion & " successfully installed." & @CRLF, $aData)
        _EventLog__Close($hEventLog)
    EndIf
EndFunc   ;==>EventLog



Func MyExit()
    Exit
EndFunc   ;==>MyExit

Func About()
    ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
    MsgBox($MB_SYSTEMMODAL, "", "Firefox Update Tool" & @CRLF & @CRLF & _
            "Version: 2.5.0.0" & @CRLF & _
            "Firefox Updater by Carm0@Sourceforge" & @CRLF & "CTRL+ALT+m to kill", 5) ; Find the folder of a full path.
EndFunc   ;==>About

Func ExitScript()
    Exit
EndFunc   ;==>ExitScript

#comments-start
    http://superuser.com/questions/823530/change-some-default-settings-for-firefox-globally
    http://mxr.mozilla.org/mozilla-release/source/browser/app/profile/firefox.js#387
    http://smallbusiness.chron.com/change-default-homepage-users-54727.html
    https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment
    https://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/
    https://wiki.mozilla.org/Installer:Command_Line_Arguments
    https://support.mozilla.org/en-US/questions/971189
    http://forums.mozillazine.org/viewtopic.php?p=2228066
    http://forums.mozillazine.org/viewtopic.php?f=38&t=2950829 ; updates auto
    http://forums.mozillazine.org/viewtopic.php?f=8&t=2753795
    http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons
    http://www.itninja.com/blog/view/deploy-popup-allowed-sites-with-firefox  deploy with certain opous enabled
#ce

Mozilla.cfg file:

//
pref("browser.search.geoSpecificDefaults", false); 
pref("browser.search.defaultenginename.US", "data:text/plain,browser.search.defaultenginename.US=Google");
//https://support.mozilla.org/en-US/questions/1034136


// set Firefox Default homepage 
defaultPref("browser.startup.homepage", "data:text/plain,browser.startup.homepage=https://www.startpage.com/do/mypage.pl?prf=381c658b828c3fe50ec7563137fef98f");

// Don't show WhatsNew on first run after every update
pref("browser.startup.homepage_override.mstone","ignore");

// disables the 'know your rights' button from displaying on first run
pref("browser.rights.3.shown", true);
pref("browser.usedOnWindows10", true);
pref("browser.rights.override", true);

// Do not perform system default browser check on startup
pref("browser.shell.checkDefaultBrowser", false);

// set all plugins to always activated - two settings
pref("plugin.default.state", 2);
// https://support.mozilla.org/en-US/questions/982143 reference about click to play flash
// set flash and silverlight always ask = 1 always activate = 2
defaultPref("plugin.state.flash", 2);

// hide choose what i share which pops up at the bottom after a minute
lockPref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
// https://groups.google.com/forum/#!topic/mozilla.support.firefox/DRXvfTA6Hnc


//disable the "Improve Firefox" suggestion
pref("toolkit.telemetry.prompted", 2);
//https://support.mozilla.org/en-US/questions/898549


// do not block popups - can only be default or locked pref
defaultPref("dom.disable_open_during_load", false);
//http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons


//lockpref("privacy.sanitize.migrateFx3Prefs", true);
// http://www.pcc-services.com/kixtart/firefox-lockdown.html
//pref("browser.privatebrowsing.autostart", true);

// prevent reader view from popping down at the top
pref("reader.parse-on-load.enabled",false);

// click to play - disabled so you are not prompted - https://support.mozilla.org/en-US/questions/934809
pref("plugins.click_to_play", false);

// below will set the cache only to clear on exit, you need to tell it what to do with the reset of the data not just cache leave cache out. Just add a '\\' to whatever you want to clear on browser exit.
//defaultPref("privacy.clearOnShutdown.cookies", false);
defaultPref("privacy.clearOnShutdown.downloads", false);
defaultPref("privacy.clearOnShutdown.formdata", false);
defaultPref("privacy.clearOnShutdown.history", false);
defaultPref("privacy.clearOnShutdown.sessions", false);
defaultPref("privacy.sanitize.migrateClearSavedPwdsOnExit", false);
defaultPref("privacy.sanitize.sanitizeOnShutdown", true);

//pref("browser.privatebrowsing.autostart", true);

//prevent autoplay  https://support.mozilla.org/en-US/questions/1103127
//defaultPref("media.autoplay.enabled", false);

//https://wiki.mozilla.org/Electrolysis
//pref("browser.tabs.remote.autostart", true);
//pref("browser.tabs.remote.force-enable", true);

// ref: http://www.itninja.com/question/firefox-22-for-enterprise-deployment-default-preferences

// Prevent refresh message showing at the bottom if firefox is not used in a while - http://techdows.com/2016/05/firefox-reinstall-to-prompt-for-a-refresh.html   https://support.mozilla.org/en-US/questions/1084402
pref("browser.disableResetPrompt", true);

// disable plugin check  - https://support.mozilla.org/en-US/questions/968056
//defaultPref("plugin.scan.plid.all",false);
//defaultPref("plugins.update.url",""); 

// disable remember preferences
//defaultPref("signon.rememberSignons", false); 


//https://twitter.com/HighTechDad/status/955916813178691584
//https://t.co/YTvSy9EBJ1
// defaultPref can also be lockPref
defaultPref("privacy.donottrackheader.enabled", true);
//defaultPref("privacy.trackingprotection.enabled", true);
lockPref("privacy.trackingprotection.introCount", 20);

 

Edited by Carm01
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ahha
      I'm using Firefox however it shows up in all browsers.  When you hover over a hyperlink and the cursor turns to a hand then in the lower left corner of the browser the actual web URL link pops up.  How does one capture that text programmatically?  I know in FF I can right click and "Copy Link" I'm wondering if there is another way.
    • By goldstar
      hey . is it possible  send message to firefox extension  and receive too?
      what is simplest way 
       
    • By MakzNovice
      I have a simple code that takes file "C:\Temp\File1.txt" and pastes it in drop area of specific firefox location ( Note : The drag drop works manually meaning firefox window supports drag and drop)  . The return value is true with no error indicating that operation successful.
      The results are not getting updated in firefox window even after exe execution completion and sleep time 20secs.
      Attached my code snippet and _FileDragDrop.au3 + text file it works 
      #include "_FileDragDrop.au3" Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client $File1 = "E:\AutoIt\DragDropFile\File1.txt" $File2 = "E:\AutoIt\DragDropFile\File2.txt" If ProcessExists("Firefox.exe") Then $hWnd = WinGetHandle("Mozilla Firefox") ; My FF tab title substring WinActivate($hWnd) Else MsgBox(64,"Error","No Firefox window found",10) EndIf $hNPPlus=WinGetHandle("[CLASS:Notepad++]") WinActivate($hNPPlus) $iRet = _FileDragDrop($hNPPlus, $File1, 75, 274) ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF) Sleep(20000) ;~ Above code to add in Notepad++ works fine ;~ Cordinate from drop file 1 - 75, 274 $iRet = _FileDragDrop($hWnd, $File1, 75, 274,'|',False) ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF) Sleep(20000) ;~ Above code to add file in firefox with title Mozilla firefox DOES NOT work Exit
       
      Repose from code -->
      Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
      Return: True @error=0, @extended=0
      Return: True @error=0, @extended=0
       
      _FileDragDrop.au3 File1.txt
    • By mLipok
      wd_capabilities.au3 UDF was changed/modified/refactored .... and commited/merged (02-12-2021) to https://github.com/Danp2/WebDriver

      WARNING: Before you start using this UDF be sure you download the recent version from: https://github.com/Danp2/WebDriver
       
      ==================================================================================================

      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • By noellarkin
      This is for those pages that seem to load when you use _FFOpenURL(), but they have a text saying "please wait while we load your page..." but according to _FFOpenURL() the page has loaded.  An example seen in popular sites is the Cloudflare page saying "Checking your browser before...". It's the opposite of pausing a script until an element is visible on a page. It takes Elements in the form of id, xpath or text search.
      Global $BrowserPort = 4242 Global $TimeOut = 60000 Global $LocalHost = "127.0.0.1" Func _FFWaitWhileElement($thiselement, $elementtype = "xpath", $timeoutms = 60000) _FFConnect($LocalHost, $BrowserPort, $TimeOut) Local $Element Local $ElementFound = 1 Local $TimeoutCountdown = 0 While $ElementFound <> 0 And $TimeoutCountdown < $timeoutms If $elementtype = "xpath" Then $Element = _FFXPath($thiselement) EndIf If $elementtype = "id" Then Local $ConstructXPath = ".//*[@id='" & $thiselement & "']" $Element = _FFXPath($ConstructXPath) EndIf ; MsgBox(0, "", $Element) Local $ElementXPathTextContent = _FFCmd("FFau3.xpath.textContent") ; MsgBox(0, "", $ElementXPathTextContent) Local $ElementXPathInnerHTML = _FFCmd("FFau3.xpath.innerHTML") ; MsgBox(0, "", $ElementXPathInnerHTML) If $ElementXPathTextContent = "_FFCmd_Err" Or $ElementXPathInnerHTML = "_FFCmd_Err" Then $ElementFound = 0 Else $ElementFound = 1 EndIf If $elementtype = "text" Then $ElementFound = _FFSearch($thiselement) ; MsgBox(0, "", $ElementFound) EndIf $TimeoutCountdown += 1000 _FFDisConnect() _FFConnect($LocalHost, $BrowserPort, $TimeOut) WEnd Return $ElementFound EndFunc _FFConnect($LocalHost, $BrowserPort, $TimeOut) _FFOpenURL("https://www.site.com/page", True) _FFWaitForElement("Please Wait...","text", 60000) MsgBox(0,"","Page finished loading") It's pretty simple, hope it helps some of you who are working with FF.au3 :)
×
×
  • Create New...