Cookie mit AHK umschreiben ...?

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 10:35

Moin BoBo,

hier hast Du Dein Spielzeug. Das Ganze ist soweit 'getestet', dass AHK beim Laden keine Fehler auswirft. Darüberhinaus gibt es keine Gewähr, d.h. Du verwendest das Skript auf eigenes Risiko.

Die im AU3-Skript verwendeten externen Namen und Pfade für die restlichen Komponenten habe ich so gelassen. Die AU3 _Chrome...() Funktionen habe ich in Chrome_...() umgetauft. Ansonsten sollte es aber genau so funktionieren wie in den AU3-Beispielen, wenn ich keine Fehler eingebaut habe. Bei der Anpassung der Funktionsköpfe bin ich irgendwann steckengeblieben.

Code: Select all

; Chrome_Startup("autohotkey.com") ; Funktionstest

; ================================================================================================================================
; Source:        www.autoitscript.com/forum/topic/154439-chrome-udf/
;
; Title:         Chrome Automation UDF Library for AutoIt3
; Filename:      Chrome.au3
; Description:   A collection of functions for automating Chrome
; Author:        seangriffin
; Version:       V0.5
; Last Update:   29/09/13
; Requirements:  AutoIt3 3.2 or higher,
;                Chrome v29 (earlier versions untested)
;                AutoIT for Google Chrome (Chrome extension)
; Changelog:     ---------29/09/13---------- v0.5
;                Changed _ChromeStartup() to exit search if chrome.exe is found.
;                ---------12/09/13---------- v0.4
;                Changed _ChromeStartup() to search various folders for chrome.exe.
;                ---------11/09/13---------- v0.3
;                Changed  Chrome_NativeMessagingHostDir to %APPDATA%.
;                Changed _ChromeShutdown() to kill all process instances.
;                ---------10/09/13---------- v0.2
;                Added _ChromeInputClickByName().
;                Added _ChromeObjGetHTMLById().
;                Added _ChromeObjGetHTMLByName().
;                Added _ChromeObjGetValueByName().
;                Added _ChromeObjGetPropertyByName().
;                ---------09/09/13---------- v0.1
;                Initial release.
; ================================================================================================================================
; Global Variables
Global Chrome_NativeMessagingHostDir := A_AppData . "\AutoIt3\Chrome Native Messaging Host"
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_Startup()
; Description ...:   Starts the Chrome browser, with optional URL.
; Syntax.........:   Chrome_Startup(Url := "about:blank", ChromePath := "C:\Program Files\Google\Chrome\Application\chrome.exe")
; Parameters ....:   Url                  - Optional: a URL to visit on startup.
;                    ChromePath           - The path to "chrome.exe".
; Return values .:   On Success           - Returns the PID of the chrome process.
;                    On Failure           - Returns False.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_Startup(Url := "about:blank", ChromePath := "") {
   Static LocalAppData := Chrome_GetLocalAppDataDir()
   If (StrLen(ChromePath) = 0)
      RegRead, ChromePath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe ; registry check
   If (StrLen(ChromePath) = 0) {
      If FileExist(A_ProgramFiles . "\Google\Chrome\Application\chrome.exe")     ; program files check
         ChromePath := A_ProgramFiles . "\Google\Chrome\Application\chrome.exe"
      Else If FileExist(A_ProgramFiles . "\Google\Chrome\chrome.exe")
         ChromePath := A_ProgramFiles . "\Google\Chrome\chrome.exe"
      Else If FileExist(A_AppData . "\Google\Chrome\Application\chrome.exe")     ; roaming application data check
         ChromePath := A_AppData . "\Google\Chrome\Application\chrome.exe"
      Else If FileExist(A_AppData . "\Google\Chrome\chrome.exe")
         ChromePath := A_AppData . "\Google\Chrome\chrome.exe"
      Else If FileExist(LocalAppData . "\Google\Chrome\Application\chrome.exe")  ; local application data check
         ChromePath := LocalAppData . "\Google\Chrome\Application\chrome.exe"
      Else If FileExist(LocalAppData . "\Google\Chrome\chrome.exe")
         ChromePath := LocalAppData . "\Google\Chrome\Application\chrome.exe"
   }
   If (StrLen(ChromePath) > 0) {
      Run, %ChromePath% "%Url%", , , PID
      Return PID
   }
   Else
      Return False
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_Shutdown()
; Description ...:   Closes the Chrome browser, and the native messaging host.
; Syntax.........:   Chrome_Shutdown()
; Return values .:   On Success           - Returns nothing.
;                    On Failure           - Returns nothing.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_Shutdown() {
   ; Close Chrome if it is currently open
   If (ChromeWin := Chrome_WinExists())
      WinClose, ahk_id %ChromeWin%
   ; Close the native messaging host (it consumes CPU if left running)
   While (NmhPID := Chrome_NmhExists()) {
      Process, Close, %NmhPID%
      Sleep, 100
   }
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_Eval()
; Description ...:   Executes a JavaScript "eval" function against the document loaded in Chrome.
; Syntax.........:   Chrome_Eval(javascript_expression, timeout := 5)
; Parameters ....:   JSExpression         - A JavaScript expression to execute.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns the result of the "eval" function as a String.
;                    On Failure           - Returns "", and:
;                                           sets ErrorLevel = 3 if there was no response from Chrome.
;                                           sets ErrorLevel = 2 if the input file for the NMH couldn't be written.
;                                           sets ErrorLevel = 1 if Chrome was unavailable.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_Eval(JSExpression, Timeout := 5) {
   Response := ""
   If Chrome_WinExists() {
      If (File := FileOpen(Chrome_NativeMessagingHostDir . "\input.txt", "w")) {
         File.Write(JSExpression)
         File.Close()
         WaitUntil := A_TickCount + (TimeOut * 1000)
         While (A_TickCount < WaitUntil) {
            If FileExist(Chrome_NativeMessagingHostDir . "\output.txt")
               Break
            Sleep, 100
         }
         If FileExist(Chrome_NativeMessagingHostDir . "\output.txt") {
            FileRead, Response, %Chrome_NativeMessagingHostDir%\output.txt
            FileDelete, %Chrome_NativeMessagingHostDir%\output.txt
         }
         Else
            ErrorLevel := 3
      }
      Else
         ErrorLevel := 2
   }
   Else
      ErrorLevel := 1
   ErrorLevel := 0
   Return Response
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_DocWaitForReadyStateCompleted()
; Description ...:   Waits for the "readyState" of the document loaded in Chrome to be "complete".
; Syntax.........:   Chrome_DocWaitForReadyStateCompleted(imeout := 5)
; Parameters ....:   Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns True.
;                    On Failure           - Returns False, and sets ErrorLevel = 1.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_DocWaitForReadyStateCompleted(Timeout := 5) {
   Response := ""
   Result := True
   Loop
      Response := Chrome_Eval("document.readyState;", Timeout)
   Until (ErrorLevel > 0) || (StrLen(Response) = 0) || (Response = "complete")
   If (ErrorLevel > 0) || (StrLen(Response) = 0) {
      Result := False
      ErrorLevel := 1
   }
   Return Result
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_InputClickByName()
; Description ...:   Clicks an <input> element based on it's "name" attribute.
; Syntax.........:   Chrome_InputClickByType(type, index := 0, timeout := 5)
; Parameters ....:   ObjName              - the value of the "name" attribute
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns "".
;                    On Failure           - Returns "", ErrorLevel is set by Chrome_Eval().
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_InputClickByName(ObjName, Index := 0, Timeout = 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "].click();", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_InputClickByType()
; Description ...:   Clicks an <input> element based on it's "type" attribute.
; Syntax.........:   Chrome_InputClickByType(type, timeout := 5)
; Parameters ....:   Type                 - the value of the "type" attribute
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns "".
;                    On Failure           - Returns "", ErrorLevel is set by Chrome_Eval().
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_InputClickByType(Type, Timeout := 5) {
   Return Chrome_Eval("_ChromeInputClickByType=" . Type, Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_DocGetTitle()
; Description ...:   Gets the <title> element of the document loaded in Chrome.
; Syntax.........:   Chrome_DocGetTitle(Timeout := 5)
; Parameters ....:   Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns the value of the <title> element.
;                    On Failure           - Returns "", ErrorLevel is set by Chrome_Eval().
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_DocGetTitle(Timeout := 5) {
   Return Chrome_Eval("document.title;", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_DocWaitForExistenceByTitle()
; Description ...:   Waits until the <title> element is a specific value.
; Syntax.........:   Chrome_DocWaitForExistenceByTitle(Title, Timeout := 5)
; Parameters ....:   Title                - the value of the <title> element
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns True.
;                    On Failure           - Returns False.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_DocWaitForExistenceByTitle(Title, Timeout := 5) {
   WaitUntil := A_TickCount + (Timeout * 1000)
   DocExists := False
   While (!DocExists) && (A_TickCount < WaitUntil) {
      If (Title = Chrome_DocGetTitle()) {
         DocExists := True
         Break
      }
      Sleep, 100
   }
   Return DocExists
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjGetHTMLById()
; Description ...:   Get the "innerHTML" attribute value of a element based on it's "name" property.
; Syntax.........:   Chrome_ObjGetHTMLById(ObjID, Timeout := 5)
; Parameters ....:   ObjID                - the value of the "id" property
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success              - Returns the "innerHTML" attribute value.
;                    On Failure              - Returns "".
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjGetHTMLById(ObjID, Timeout := 5) {
   Return Chrome_Eval("document.getElementById('" . ObjID . "').innerHTML;", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjGetHTMLByName()
; Description ...:   Get the "innerHTML" attribute value of a element based on it's "name" property.
; Syntax.........:   Chrome_ObjGetHTMLByName(ObjName, Index := 0, Timeout = 5)
; Parameters ....:   ObjName              - the value of the "name" property
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns the "innerHTML" attribute value.
;                    On Failure           - Returns "".
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjGetHTMLByName(ObjName, Index := 0, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "].innerHTML;", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjGetHTMLByTagName()
; Description ...:   Get the "innerHTML" attribute value of a element based on it's "tagName" property.
; Syntax.........:   Chrome_ObjGetHTMLByTagName(TagName, Index := 0, Timeout := 5)
; Parameters ....:   TagName              - the value of the "tagName" property (i.e. "h1", "p")
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns the "innerHTML" attribute value.
;                    On Failure           - Returns "".
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjGetHTMLByTagName(TagName, Index := 0, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByTagName('" . TagName . "')[" . Index . "].innerHTML;", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjGetValueByName()
; Description ...:   Gets the value of an element based on it's "name" attribute.
; Syntax.........:   Chrome_ObjGetValueByName(ObjName, Index := 0, Timeout := 5)
; Parameters ....:   ObjName              - the value of the "name" attribute
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns Value.
;                    On Failure           - Returns ""
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjGetValueByName(ObjName, Index := 0, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "].value;", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjSetValueByName()
; Description ...:   Sets the "value" attribute of a element based on it's "name" attribute.
; Syntax.........:   Chrome_ObjSetValueByName(ObjName, Value, Index := 0, Timeout := 5)
; Parameters ....:   ObjName              - the value of the "name" attribute
;                    Value                - The text to set the "value" attribute to
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns $value.
;                    On Failure           - Returns "", and sets @ERROR = 2.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjSetValueByName(ObjName, Value, Index := 0, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "].value = '" . Value . "';", Timeout)
}
; #FUNCTION# =====================================)===============================================================================
; Name...........:   Chrome_InputSetCheckedByName()
; Description ...:   Sets the "checked" attribute of an <input> element based on it's "name" attribute.
; Syntax.........:   Chrome_InputSetCheckedByName(ObjName, Value, Index := 0, Timeout := 5)
; Parameters ....:   ObjName              - the value of the "name" attribute
;                    Value                - The boolean to set the "checked" attribute to
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns Value.
;                    On Failure           - Returns "", and sets @ERROR = 2.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_InputSetCheckedByName(ObjName, Value, Index := 0, Timeout := 5) {
   Value := Value ? "True" : "False"
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "].checked = " . Value . ";", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_OptionSelectWithTextByObjName()
; Description ...:   Selects an <option> element with a specific "text" based on it's <select> element "name" attribute.
; Syntax.........:   Chrome_OptionSelectWithTextByObjName(OptionText, ObjName, Timeout := 5)
; Parameters ....:   OptionText           - the text of the <option> element
;                    ObjName              - the value of the <select> element's "name" attribute
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns "".
;                    On Failure           - Returns "", and sets @ERROR = 2.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_OptionSelectWithTextByObjName(OptionText, ObjName, Timeout := 5) {
   Return Chrome_Eval("_ChromeOptionSelectWithTextByObjName=" . OptionText . "|" . ObjName, Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_OptionSelectWithValueByObjName()
; Description ...:   Selects an <option> element with a specific "value" based on it's <select> element "name" attribute.
; Syntax.........:   Chrome_OptionSelectWithValueByObjName(OptionValue, ObjName, Timeout := 5)
; Parameters ....:   OptionValue          - the value of the <option> element
;                    ObjName              - the value of the <select> element's "name" attribute
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns $option_value.
;                    On Failure           - Returns "", and sets @ERROR = 2.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_OptionSelectWithValueByObjName(OptionValue, ObjName, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[0].value = '" . OptionValue . "';", Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_InputSetCheckedWithValueByName()
; Description ...:   Sets the "checked" attribute of an element with a specific "value" based on it's "name" attribute.
; Syntax.........:   Chrome_InputSetCheckedWithValueByName(InputValue, ObjName, Checked, Timeout := 5)
; Parameters ....:   InputValue           - the value of the element
;                    ObjName              - the value of the element's "name" attribute
;                    Checked              - the boolean value of the "checked" attribute
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns "".
;                    On Failure           - Returns "", and sets @ERROR = 2.
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_InputSetCheckedWithValueByName(InputValue, ObjName, Checked, Timeout := 5) {
   Checked := Checked ? "True" : "False"
   Return Chrome_Eval("_ChromeInputSetCheckedWithValueByName=" . InputValue . "|" . ObjName . "|" . Checked, Timeout)
}
; #FUNCTION# =====================================================================================================================
; Name...........:   Chrome_ObjGetPropertyByName()
; Description ...:   Get the value of a specific property of a element based on it's "name" property.
; Syntax.........:   Chrome_ObjGetPropertyByName(objname, propertyname, index := 0, timeout := 5)
; Parameters ....:   ObjName              - the value of the "name" property
;                    PropertyName         - the name of the property
;                    Index                - Optional: the index of the element if many are found.
;                    Timeout              - Optional: a number of minutes before exiting the function.
; Return values .:   On Success           - Returns the "innerHTML" attribute value.
;                    On Failure           - Returns "".
; Author ........:   seangriffin
; Modified.......:
; Remarks .......:   A prerequisite is that the Chrome browser is open
;                    (Window title = "[REGEXPTITLE:.*- Google Chrome]").
; Related .......:
; Link ..........:
; Example .......:   Yes
; ================================================================================================================================
Chrome_ObjGetPropertyByName(ObjName, PropertyName, Index := 0, Timeout := 5) {
   Return Chrome_Eval("document.getElementsByName('" . ObjName . "')[" . Index . "]." . PropertyName . ";", Timeout)
}
; ================================================================================================================================
; Auxiliary functions for internal use.
; ================================================================================================================================
Chrome_GetLocalAppDataDir() {
   ; CSIDL_LOCAL_APPDATA = 0x001C
   VarSetCapacity(SFP, 2 * 260, 0) ; special folder path
   Return (DllCall("Shell32.dll\SHGetSpecialFolderPath", "Ptr", 0, "Str", SFP, "Int", 0x1C, "UInt", 0, "UInt") ? SFP : "")
}
; ================================================================================================================================
Chrome_NmhExists() {
   Process, Exist, autoit-chrome-native-messaging-host.exe
   Return %ErrorLevel%
}
; ================================================================================================================================
Chrome_WinExists() {
   TitleMatchMode := A_TitleMatchMode
   SetTitleMatchmode, Regex
   ChromeWin := WinExist(".*- Google Chrome")
   SetTitleMatchmode, %TitleMatchMode%
   Return ChromeWin
}
Als Gegenleistung erwarte ich, dass Du Dich nicht mehr ohne besonderen Grund versteckst. Meiner Meinung nach sollte das ein Moderator nicht tun, um kein 'schlechtes Beispiel' für Andere zu liefern. ;)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 11:30

Ooops :o
Das ging ja äußerst zügig - was mich früher zu folgender aussage veranlaßt hätte: "Mensch, du versaust uns den Akkord!" :lol:
TBH, ich hatte da mit so ca. einer funktion pro woche gerechnet! R-E-S-P-E-K-T :thumbup:

BTW! (8ung! Columbo-effekt!!) ... ich hätte da mal noch eine Frage:
Der Native Messaging Host (vormals ein kompiliertes python script, nach aussage im AU3 thread letztmals ein kompiliertes AU3 script). Ein dekompilieren desselben ziehe ich NICHT in betracht.
Aus gründen der maintenance wäre es jedoch sicher angeraten dies in nativem AHK (bzw, offen liegendem code) zu haben? Siehst du (nach review der dokumentation [hier] und/oder [hier]) dazu eine chance?? Eine verbesserung wäre es sicher, die kommunikation zur browser-extension unter umgehung des read/write zu erreichen.

So, ich werd mal schaun ob ich meinen teil zum laufen bekomme (angstschweissporen öffnen sich kanaldeckelgroß...) :shifty:

PS. Ich musste erstmal überlegen was du mit "verstecken" meinst :lol: Wer mal stalkende gamer am bein hatte wird halt schon mal ebbes paranoid ;)
PPS. ich habe die thematik des NMH auch in FireFox-Artikeln gesehen. Überhaupt scheint mir das thema der browsererweiterung zw FF und Chrome anwendungsübergreifend zu sein? Könnte demnach gut sein, das die FireFoxer unter uns gleich mit beglückbar wären, oder? :xmas:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 11:40

Fast vergessen. Mit einer zurückliegenden Chrome umstellung ist die erfassung der target fenster gebrochen (soweit aus dem thread) möglicherweise braucht es dazu noch einen fix im code.

; Wildcarding der fenstertitel scheint gebrochen ...
; https://www.autoitscript.com/forum/topi ... nt-1165993
; ... die lösung dazu ?
; https://www.autoitscript.com/forum/topi ... nt-1166023

8-)
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 11:49

So besser?

Code: Select all

Chrome_WinExists() {
   Return WinExist("ahk_class Chrome_WidgetWin_1")
}
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 11:53

Zum NMH: Ohne Sourcecode als Vorlage weiß ich nicht mal, wo ich anfangen soll.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 13:26

Ich stehe hier etwas auf dem schlauch. Zur Chrome.au3 (welche just-me konvertiert hat) gibt es jeweils zwei test/beispiel-dateien. Darin wird im AU3-code die native funktion ConsoleWrite() verwendet.

Die AU3 hilfe sagt dazu ...
"ConsoleWrite
Writes data to the STDOUT stream. Some text editors can read this stream as can other programs which may be expecting data on this stream."


Für diese sehe ich keine entsprechung bei AHK? Gibts dazu etwas (inoffizielles/eine UDF)??

Code: Select all

; Get the "value" attribute of the "hiddenExample" hidden input element
ConsoleWrite("_ChromeObjGetValueByName(""hiddenExample"") = " & _ChromeObjGetValueByName("hiddenExample") & @CRLF)   ; au3
ConsoleWrite("Chrome_ObjGetValueByName(""hiddenExample"") = " . Chrome_ObjGetValueByName("hiddenExample") . "`n`r")   ; ahk

; Set the "value" attribute of the "textExample" text input element to a random string
ConsoleWrite("_ChromeObjSetValueByName(""textExample"", _RandomText(10)) = " & _ChromeObjSetValueByName("textExample", _RandomText(10)) & @CRLF) ; au3
ConsoleWrite("Chrome_ObjSetValueByName("textExample", RandomText(10)) = " . Chrome_ObjSetValueByName("textExample", RandomText(10)) . "`n`r")   ; ahk
.
.
.

Func _RandomText($length)   ; au3
    $text = ""
    For $i = 1 To $length
        $text &= Chr(Random(65, 90, 1))
    Next
    Return $text
EndFunc   ;==>_RandomText
.
.
.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 16:11

Hier ein Native Messaging Host in Delphi gebuxelt. 100% böhmisches dorf (at least for me):
https://medium.com/@svanas/chrome-nativ ... f8f91cdce6
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

29 Nov 2017, 17:00

Wenn Du das nur mal testen willst, ist die AU3-Funktion ConsoleWrite() unwichtig. Du kannst das erst einmal einfach so 'übersetzen':

Code: Select all

ConsoleWrite("_ChromeObjGetValueByName(""hiddenExample"") = " & _ChromeObjGetValueByName("hiddenExample") & @CRLF)  ; au3
; wird zu
MsgBox, 0, Chrome_ObjGetValueByName("hiddenExample"), % Chrome_ObjGetValueByName("hiddenExample") ; ahk
(zumindest theoretisch)

NMH: Ich war vor Jahren mal fast so weit, mich mit Delphi zu beschäftigen. Ich habe es dann aber doch nicht getan und kann deshalb kaum erahnen, wie man das portieren könnte.
Ein Beispiel in COBOL wäre ideal. ;)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 02:16

COBOL :o

Das C++ file chrome_interface :arrow: [hier] scheint mir dann doch etwas geläufiger zu sein. Lässt sich denn das nach AHK übersetzen?
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 02:59

Moin,

möglicherweise, aber dazu müsste sich jemand finden, der die Mechanisman im Hintergrund versteht.

Lassen sich die mit dem AU3-Skript verteilten Browser-Komponenten überhaupt installieren und gibt es irgendeine erfolgreiche Kommunikation mit dem portierten AHK-Skript? Das tauscht ja wie auch das AU3-Skript die Informationen über fest definierte Textdateien aus, nicht über STDIN/STDOUT.

Die Schlüsselfunktion ist Chrome_Eval(). Der Rest ist eher schmückendes Beiwerk. Für einen JS-Kundigen sollte es deshalb recht einfach sein, die Grundfunktionalität zu testen.
Last edited by just me on 30 Nov 2017, 03:07, edited 1 time in total.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 03:21

Der kompilierte Python Code wäre als Source sehr interessant zu haben.
Recommends AHK Studio
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 04:09

nnnik wrote:Der kompilierte Python Code wäre als Source sehr interessant zu haben.
Sowas wie [hier] von [hier]? Wobei dieser [hier] noch nachbearbeitet wurde, da der Google beispielcode zwischenztl veraltet war.

BTW, im AU3 wurde ebenfalls angemerkt das in das kompilat eine python-dll includiert wurde. J4TR. Have fun :mrgreen:

BoBo 8-) (der ziemlich frustriert ist da Apple den App Store aus iTunes entfernt hat :x )
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 04:16

Ist das auch die Version die AutoIt verwendet?
Recommends AHK Studio
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 04:31

nnnik wrote:Ist das auch die Version die AutoIt verwendet?
TBH - bin ich überfragt!?!
Hier was zur Python version/dll ...
https://www.autoitscript.com/forum/topi ... nt-1115173
... und hier die anmerkung zur ersetzung durch einen AU3 NMH (weshalb auch die Python.exe nur noch schwer erhältlich sein dürfte)
https://www.autoitscript.com/forum/topi ... nt-1119940

Den AU3 thread selbst nochmal in gänze zu lesen macht wahrscheinlich sinn, zumal mir mangels kenntnis evtl etwas maßgebliches durch die lappen gegangen sein könnte :shifty:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 11:44

Falls ich es noch nicht kund getan habe, Chrome_Startup() und Chrome_ShutDown() haben schon mal anstandslos funktioniert :dance:

And yep, it wasn't me.
Full credit goes to :arrow: just-me :ugeek: - and of course to our unknown mate "Mr. AutoIT 2013" :arrow: Sean Griffin :salute: :beard: :salute:
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 16:49

Hallo BoBo,

es mag Dich enttäuschen, aber Chrome_Startup() und Chrome_Shutdown() sind wohl die einzigen 'Core'-Funktionen, die ohne NMH auskommen.

Ich habe den AutoIt-Beitrag schon mehrfach durchgekaut. Und ich habe dabei Zweifel bekommen, ob das mit auch dem originalen AU3-Skript überhaupt noch funktioniert. SeanGriffin hält sich jedenfalls seit einiger Zeit sehr zurück.

Es gibt ja einige AHK-User, die auch AutoIt nutzen. Vielleicht könnte einer von Denen es mal probieren.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

30 Nov 2017, 18:10

Stimmt. :lol: Gab schon reichlich vorschußlorbeeren. Spricht ja nichts gegen gute stimmung ;)

Welly well. Den NMH habe ich erstmal vom APPDATA-pfad verchoben, da dieser ein system-pfad zu sein scheint und ich mir nicht sicher bin inwieweit dort bereits system-restriktionen zu berücksichtigen wären? Daraus resultierte dann eine notwendige Pfad- und extension ID anpassung in der datei "manifest.jason" im NMH directory, sowie die pfadanpassung in der registry. Bei der fenstererkennung, einer vorbedingung zur javascript evaluation, bekomme ich keinen echten namen gegriffen, sondern es werden hex-werte retourniert. Da diese jedoch nur schwerlich mit dem zu vergleichenden text-pattern matchen, greifen danach lediglich die timeouts.
Dasamavolldoof :? Ich hoffe jetzt einfach mal das der fehler vor der tastatur sitzt ...

In der evaluierungs-sektion/funktion sollte allerdings das anlegen der "input.txt" per se funktionieren (ich denke mal die output.txt enthält die rückmeldung des browsers). Tuts allerdings nicht. Deswegen hatte ich, wie eingangs erwähnt den pfad geändert, falls fehlende schreibrechte ein thema gewesen wären. Nun, ich bin aktuell als "admin" unterwegs. Sollte also IMHO noch kein problem darstellen.

Was sich mir bisher nicht erklärt ist, das der NMH zwar wie beabsichtigt mit dem shutdown von chrome ebenfalls schließt, ich jedoch nirgends erkenne wann und wo dieser gestartet wird?
Dazu muß zur laufzeit eine chrome browserinstanz bestehen, denn ohne aktuelle instanz klappt der NMH (ein konsolenfenster) einfach wieder zusammen.
Erklärung dazu findet sich [hier] :shifty:

So, BoBo macht jetzt BuBu. Bis morgen(s). Greetz 8-)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Cookie mit AHK umschreiben ...?

01 Dec 2017, 03:30

Moin gemeinde :)
Es funzt was! Es ist mir gelungen den NMH (im stealth mode!) mit dem browser zu starten <"lust auf champus vor 18:00 verspür"-smiley> UND <trommelwirbel> bei übergabe einer input.txt mit der anfrage zum fenstertitel retournierte prompt eine output.txt mit der korrekten angabe! :thumbup:

input.txt

Code: Select all

document.title;
output.txt

Code: Select all

{"text":"AutoHotkey Community - Index page"}
Stay tuned ...

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 22 guests