Sign in to follow this  
Followers 0
ileandros

Tcp

7 posts in this topic

#1 ·  Posted (edited)

Hello,

First of all sry for the tittle but i couldn't find something better atm.

Ok so, i am trying to automate Chrome browser.

I got the FF.au3 UDF and tried to change it in Chrome so i could make use to it but i am getting problems...

I never used TCP before so im not sure im understanding the entire code.

This is what i made until now:

#Region Global Constants
Global Const $_GC_PROC_NAME = "chrome.exe"
Global Const $_GC_COM_DELAY_MAX = 200
Global Enum $_GC_ERROR_Success = 0, _
$_GC_ERROR_GeneralError, _
$_GC_ERROR_SocketError, _
$_GC_ERROR_InvalidDataType, _
$_GC_ERROR_InvalidValue, _
$_GC_ERROR_SendRecv, _
$_GC_ERROR_Timeout, _
$_GC_ERROR___UNUSED, _
$_GC_ERROR_NoMatch, _
$_GC_ERROR_RetValue, _
$_GC_ERROR_ReplException, _
$_GC_ERROR_InvalidExpression
#EndRegion Global Constants
#Region Global Variables
Global $_GC_GLOBAL_SOCKET = -1
Global $_GC_CON_DELAY
Global $_GC_LOADWAIT_TIMEOUT = 120000
Global $_GC_LOADWAIT_STOP = True
Global $_GC_COM_TRACE = True
Global $_GC_ERROR_MSGBOX = True
Global $_GC_FRAME = 'top'
Global $_GC_SEARCH_MODE = 0
#EndRegion Global Variables
_GCAction("back")
Func _GCAction($sAction, $vOption = "", $vOption2 = "", $bLoadWait = True)
Local Const $sFuncName = "_GCAction"
Local $sCommand
Local $sActionL = StringLower($sAction)
Select
Case $sActionL = "back"
$sCommand = "gBrowser.goBack()"
Case $sActionL = "home"
$sCommand = "gBrowser.goHome()"
Case $sActionL = "forward"
$sCommand = "gBrowser.goForward()"
EndSelect
Local $sRet = _GCComand($sCommand)
If Not @error Then
Return $sRet
Else
SetError(@error)
Return ""
EndIf
EndFunc

Func _GCComand($sArg, $iTimeOut = 30000)
Local Const $sFuncName = "_GCComand"
Local $sRet
If StringLeft($sArg, 1) = "." Then $sArg = "window.content.document" & $sArg
Local $sArgWrapped = StringReplace($sArg, "window.content.document", "window.content.wrappedJSObject.document")
$sArg = StringReplace($sArg, "window.content.document", "window.content." & $_GC_FRAME & ".document")
$sArgWrapped = StringReplace($sArgWrapped, "window.content.wrappedJSObject.document", "window.content.wrappedJSObject." & $_GC_FRAME & ".document")
If (Not StringInStr($sArg, ".frames[")) Or StringInStr($sArg, "evaluate") Or (Not StringRegExp($sArg, "\.[a-zA-z]+\(.*?\)(\[.+\])?\.", 0)) Then
If __GCSend($sArg) Then
$sRet = __GCRecv($iTimeOut)
If Not @error Or String($sRet) <> "_GCComand_Err" Then
    Return $sRet
ElseIf StringInStr($sArgWrapped, "wrappedJSObject") Then
    __GCSend($sArgWrapped)
    $sRet = __GCRecv($iTimeOut)
    If Not @error And String($sRet) <> "_GCComand_Err" Then Return $sRet
EndIf
EndIf
Else
__GCSend($sArgWrapped)
$sRet = __GCRecv($iTimeOut)
If Not @error And String($sRet) <> "_GCComand_Err" Then Return $sRet
EndIf
SetError(__GCError($sFuncName, $_GC_ERROR_RetValue, $sRet))
Return ""
EndFunc
Func __GCError($sWhere, Const ByRef $i_FF_ERROR, $sMessage = "")
Local $sOut, $sMsg
Sleep(200)
Switch $i_FF_ERROR
Case $_GC_ERROR_Success
Return $_GC_ERROR_Success
Case $_GC_ERROR_GeneralError
$sOut = "General Error"
Case $_GC_ERROR_SocketError
$sOut = "Socket Error"
Case $_GC_ERROR_InvalidDataType
$sOut = "Invalid data type"
Case $_GC_ERROR_InvalidValue
$sOut = "Invalid value"
Case $_GC_ERROR_Timeout
$sOut = "Timeout"
Case $_GC_ERROR_NoMatch
$sOut = "No match"
Case $_GC_ERROR_RetValue
$sOut = "Error return value"
Case $_GC_ERROR_SendRecv
$sOut = "Error TCPSend / TCPRecv"
Case $_GC_ERROR_ReplException
$sOut = "MozRepl Exception"
Case $_GC_ERROR_InvalidExpression
$sOut = "Invalid Expression"
EndSwitch
If $sMessage = "" Then
$sMsg = $sWhere & " ==> " & $sOut & @CRLF
ConsoleWriteError($sMsg)
Else
$sMsg = $sWhere & " ==> " & $sOut & ": " & $sMessage & @CRLF
ConsoleWriteError($sMsg)
EndIf
Return $i_FF_ERROR
EndFunc ;==>__FFError

Func __GCSend($sCommand)
Local Const $sFuncName = "__GCSend"
If Not __GCIsSocket($_GC_GLOBAL_SOCKET) Then
SetError(__GCError($sFuncName, $_GC_ERROR_SocketError))
Return 0
EndIf
TCPSend($_GC_GLOBAL_SOCKET, $sCommand & @CRLF)
If Not @error Then
If $_GC_COM_TRACE Then ConsoleWrite("__GCSend: " & $sCommand & @CRLF)
Return 1
Else
SetError(__GCError($sFuncName, $_GC_ERROR_SendRecv, "TCPSend: " & $sCommand))
Return 0
EndIf
EndFunc

Func __GCRecv($iTimeOut = 30000)
Local $sRet = __GCWaitForRepl($iTimeOut)
Local $iErr = @error
$sRet = StringStripWS($sRet, 3)
If StringLeft($sRet, 1) = '"' Then $sRet = StringTrimLeft($sRet, 1)
If StringRight($sRet, 1) = '"' Then $sRet = StringTrimRight($sRet, 1)
If $sRet = "true" Then
$sRet = 1
ElseIf $sRet = "false" Then
$sRet = 0
EndIf
If $_GC_COM_TRACE Then ConsoleWrite("__FFRecv: " & $sRet & @CRLF)
SetError($iErr)
Return $sRet
EndFunc

Func __GCIsSocket(ByRef $Socket)
Return ($Socket > 0 And IsInt($Socket))
EndFunc

Func __GCWaitForRepl($iTimeOut)
Local Const $sFuncName = @CRLF & "__GCWaitForRepl"
Local $recv, $sRet = "", $TimeOutTimer = TimerInit()
If $iTimeOut < 200 Then $iTimeOut = 200
While TimerDiff($TimeOutTimer) < $iTimeOut
Sleep($_GC_CON_DELAY)
$recv = TCPRecv($_GC_GLOBAL_SOCKET, 4096)
If @error Then
SetError(__GCError($sFuncName, $_GC_ERROR_SendRecv, "TCPRecv :" & @error))
Return ""
EndIf
$sRet &= $recv
If StringRegExp($recv, "!!!(.*?)(TypeError|Exception|ReferenceError):?") Then
$recv = StringLeft($recv, StringInStr($recv, "location") - 1)
Sleep(200)
SetError(__GCError($sFuncName, $_GC_ERROR_ReplException, StringStripWS($recv, 3)))
__GCSend(";")
Sleep(200)
Return ""
ElseIf StringInStr($recv, "....>") Then
__GCSend(";")
Sleep(200)
SetError(__GCError($sFuncName, $_GC_ERROR_RetValue, "MozRepl ....>"))
Return ""
ElseIf StringInStr($recv, "beginning of the line to force evaluation") Then
Sleep(500)
EndIf
If StringRegExp($recv, "repl[\d]?>") Then Return StringRegExpReplace($sRet, "repl[\d]?>", "")
WEnd
SetError(__GCError($sFuncName, $_GC_ERROR_Timeout, Round(TimerDiff($TimeOutTimer)) & "ms > " & $iTimeOut & "ms $iTimeOut"))
Return ""
EndFunc

Consolewrite im getting is:

__GCSend ==> Socket Error

_GCComand ==> Error return value

I m four hours here making this thing to work but i cant get it fixed.

All ideas would be greatly appreciated

Edit: Reading the developer site of mozilla i think i got it a bit wrong...

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites



Why are you reading the Mozilla site for the Chrome browser? Also, the mozrepl is a firefox addon, not a chrome addon.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Why are you reading the Mozilla site for the Chrome browser? Also, the mozrepl is a firefox addon, not a chrome addon.

Because i am trying to understand the code. I know mozrepl is a firefox addon and not a chrome.... thanks.

As i said i never used TCP before.

Can you understand the code above?

Can you tell me how the GCComand (ffcmd) should be used for Chrome?


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think you do not understand, what BrewMan means...

You cannot control Chrome with TCP!

The FF.au3 uses the FireFox-PlugIn 'MozRepl', wich allows you to control the browser with TCP (That's the reason why there are so much TCP commands in this UDF).

But this PlugIn is FireFox only, and as far as i know, not available for Chrome (yet)...

chess

Edited by chesstiger

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Search ChromeJS. FireFox started working on a UDF a while back.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I think you do not understand, what BrewMan means...

You cannot control Chrome with TCP!

The FF.au3 uses the FireFox-PlugIn 'MozRepl', wich allows you to control the browser with TCP (That's the reason why there are so much TCP commands in this UDF).

But this PlugIn is FireFox only, and as far as i know, not available for Chrome (yet)...

chess

Yes i came up with that this morning trying to find a solution and i found what guiness said....

Search ChromeJS. FireFox started working on a UDF a while back.

But it is really complicated and i need that API to be capable to automate Google Chrome. I think that FF udf is useless in this case so it was a bad start...

Anyway thanks for the lights guys ;)


I feel nothing.It feels great.

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
Sign in to follow this  
Followers 0