ChromeRemoteObject for Chrome.ahk

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

ChromeRemoteObject for Chrome.ahk

Post by neovis » 21 Sep 2022, 05:32

Source on Github

Depends on Chrome.ahk by geek.

The eval method is automatically added, and if a js object is returned, it is returned as an native AutoHotkey object.

Example:

Code: Select all

browser := new Chrome(a_scriptDir "\ChromeProfile")
page := browser.getPage()

doc := page.eval("document")
doc.querySelector("body").innerHTML := "
(ltrim
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
)"
doc.querySelectorAll("li")[0].innerHTML := "<a href='https://autohotkey.com'>AutoHotkey</a>"
doc.querySelectorAll("li")[3].innerHTML := "<a href='https://google.com'>Google</a>"

for i, elem in (doc.querySelectorAll("a"), text := "")
    text .= elem.innerText " (" elem.getAttribute("href") ")`n"
MsgBox % text

func := page.eval("(function(a, b) { return a + b })")
MsgBox % func.call("", 3, 5)

arr := page.eval("['hello', 'world']")
for i, v in (arr, text := "")
    text .= i ": " v "`n"
MsgBox % text

js := page.eval("window")
js.myVar := "ahk is awsome"
MsgBox % page.eval("myVar")
Recommended Fixes:
Call method of file 'Chrome.ahk' at line 245

Code: Select all

while !this.responses[ID]
    Sleep 0 ; set delay to 0 for fast response

Return to “Scripts and Functions (v1)”