WebView2

Post your working scripts, libraries and tools.
userXeo1
Posts: 39
Joined: 26 Feb 2020, 09:12

Re: 2.0-beta.1 - WebView2

Post by userXeo1 » 09 May 2022, 23:33

I am so confused, I am not able to perform simple action, such as pressing button, timing issue?:

Code: Select all

g := Gui()
g.Show(Format("w{} h{}", A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
wv := WebView2.create(g.Hwnd)
nav_sync := SyncHandler()
exec_sync := SyncHandler((args) => OutputDebug(StrGet(args[2])))
wv.CoreWebView2.add_NavigationCompleted(nav_sync)
wv.CoreWebView2.Navigate("https://sso.hhs.state.ma.us")
nav_sync.wait()
wv.CoreWebView2.ExecuteScript(
"document.getElementById('loginForm').submit()",
exec_sync
)


class SyncHandler extends WebView2.Handler {
	__New(cb := 0) {
		this.obj := SyncHandler.CompletedEventHandler()
		this.obj.cb := cb
		super.__New(this.obj, 3)
	}
	wait() {
		o := this.obj
		while !o.status
			Sleep(10)
		o.status := 0, Sleep(100)
	}
	
	class CompletedEventHandler {
		status := 0, cb := 0
		call(handler, args*) {
			if this.cb
				(this.cb)(args)
			this.status := 1
		}
	}
}
I have had luck with using NavigationCompletedEventHandler and ExecuteScriptCompletedHandle as shown in my previous post, but then when I try to load 2nd url it fails. .. :headwall:

Thank you.

userXeo1
Posts: 39
Joined: 26 Feb 2020, 09:12

Re: 2.0-beta.1 - WebView2

Post by userXeo1 » 21 Nov 2022, 14:31

Hi all,

Does anyone has working sample of connecting to existing WebView2 and getting data from page.. Something like that was done with WBGet() function:

Code: Select all

wb := WBGet("Page Title")
streetAddress:= wb.document.getElementById("strAddress").value
Thank you in advance.

User avatar
thqby
Posts: 406
Joined: 16 Apr 2021, 11:18
Contact:

Re: 2.0-beta.1 - WebView2

Post by thqby » 22 Nov 2022, 09:50

WebView2 does not have an IDispatch interface, used as code similar to the above.

The first way is to master script that start the webview2 execute javascript through ExecuteScript, and then postMessage or call the host object to pass to the ahk side.


The second is to launch in debug mode and connect with the chrome library (I haven't tried this yet).

userXeo1
Posts: 39
Joined: 26 Feb 2020, 09:12

Re: 2.0-beta.1 - WebView2

Post by userXeo1 » 23 Nov 2022, 00:42

Thank you for informative reply..

I am researching second method.. connect via debugger..

While reading a lot of docs.. especially:
https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/webview2-idl?view=webview2-1.0.1293.44#createcorewebview2environmentwithoptions

Any idea how to set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS in ahk or not sure?
To enable debugging of the targets identified by the JSON, you must set the WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variable to send --remote-debugging-port={port_num}
Thank you.

User avatar
thqby
Posts: 406
Joined: 16 Apr 2021, 11:18
Contact:

Re: 2.0-beta.1 - WebView2

Post by thqby » 26 Nov 2022, 07:36

userXeo1 wrote:
23 Nov 2022, 00:42
Any idea how to set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS in ahk or not sure?
EnvSet?

I've added optional Settings for EnvironmentOptions, allows additional command line arguments to be passed in.
WebView2.create(hwnd,,,,,{AdditionalBrowserArguments:'--remote-debugging-port=9222'})

userXeo1
Posts: 39
Joined: 26 Feb 2020, 09:12

Re: 2.0-beta.1 - WebView2

Post by userXeo1 » 30 Nov 2022, 22:02

Thank you so much!!.. Can't wait to till I post working sample..

xroot
Posts: 40
Joined: 21 Jun 2019, 08:45

[V2-rc.2 WebView2 Window 10 64bit] Christmas Tree and Snow

Post by xroot » 03 Dec 2022, 13:22

Here is a simple WebView2 Xmas tree with some snow.

Put the XmasImages.ahk in the Lib directory of WebView2.
Take the 2 off of xMasTree2 and you will get a different Xmas Tree.

Code: Select all

#Include lib\webview2.ahk
#Include lib\xmasimages.ahk

NavStr := Format("
(
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.0.min.js"></script>
    <body bgColor="black" style="overflow:hidden">
    <img src="{}" style="left:0px;top:0px;width:100%;height:100%;position:absolute">
    <img id="img0" src="{}" style="left:720px;top:150px;width:650px;height:450px;position:absolute">
    <img id="img1" src="{}" style="left:0px;top:0px;width:100%;height:100%;position:absolute;display:none">
    <img id="img2" src="{}" style="left:0px;top:0px;width:100%;height:100%;position:absolute;display:none">
    <img id="img3" src="{}" style="left:0px;top:0px;width:100%;height:100%;position:absolute;display:none">
    <script>
        var rand = [];
        for(var i=0;i<4;i++){
            rand.push(Math.floor(Math.random()*(16000-6000+1))+6000);}
        setInterval(function(){$("#img3").fadeToggle("slow")},rand[0]);
        setInterval(function(){$("#img2").fadeToggle("slow")},rand[1]);
        setInterval(function(){$("#img1").fadeToggle("slow")},rand[2]);
        setInterval(function(){$("#img0").fadeToggle("slow")},rand[3]);
    </script>
)",xMasTree2,MerryXmas,snow,snow1,snow2)

win := Gui("-Caption","WebView2 Xmas")
win.BackColor := "Black"
win.Show "Maximize"  

wv := WebView2.create(win.hWnd)
wv.CoreWebView2.NavigateToString(NavStr)

Esc::ExitApp
:xmas:
XmasImages.zip
(1.86 MiB) Downloaded 161 times

Elendiar
Posts: 17
Joined: 03 Jul 2018, 05:44

Re: 2.0-beta.1 - WebView2

Post by Elendiar » 06 Dec 2022, 07:10

Hi, nice lib, but how start webview with disabled hardware acceleration for use with winSetTransColor?

Pasukun
Posts: 3
Joined: 10 Jan 2023, 16:44

Re: 2.0-beta.1 - WebView2

Post by Pasukun » 11 Jan 2023, 10:40

Hello, I am trying to load the Edge browser under AHK GUI, but I keep running into an issue.

Image

Here is what I have done so far.

1) I have downloaded and installed AHK 2.0-beta.15.
2) I verified that I have Microsoft Edge WebView2 runtime installed on my machine.
3) I downloaded WebView2.ahk script file, 32bit and 64 bit folders, along with the DLL file in them, into my test script folder for simplicity.
4) I downloaded ComVar.ahk script file into my script folder as well.
5) I changed #Include '..\ComVar.ahk' to #Include 'ComVar.ahk' in the WebView2.ahk.
6) Ran test script using #Include 'WebView2.ahk'

Here is the test script

Code: Select all

#Include 'WebView2.ahk'

g := Gui()
g.Show('w800 h600')
wvc := WebView2.create(g.Hwnd)
wv := wvc.CoreWebView2
wv.Navigate('https://autohotkey.com')
MsgBox('Wait for loading to complete')
PrintToPdf(wv, A_ScriptDir "\11.pdf")
I have no idea how this magic supposes to work, but desperate to make it happen.

Thank you very much for your time!

User avatar
thqby
Posts: 406
Joined: 16 Apr 2021, 11:18
Contact:

Re: WebView2

Post by thqby » 11 Jan 2023, 19:20

@Pasukun
teadrinker wrote:
11 Jan 2023, 00:27
Where from? Try this one and this ComVar.ahk.
teadrinker already told you. You used the wrong version of comvar.

Tre4shunter
Posts: 139
Joined: 26 Jan 2016, 16:05

Re: WebView2

Post by Tre4shunter » 13 Feb 2023, 19:04

Is there any major reasons to use 'AddHostObjectToScript' to transmit messages between AHK and the JS in your webpage, over simple Post/SendMessages?

I know you can execute the 'AddHostObjectToScript' as Synchronous or ASnyc, which is useful, and pass/return data back and forth.

In this simple snippet, i notice the 'TryGetWebMessageAsString' - does this imply 'trying' because it fails sometimes?

Code: Select all

PageLoadCompletedHandler(handler,ICoreWebView2, Args){
	MsgBox('loaded')
	wv["main"].add_WebMessageReceived(WebView2.Handler(WebMessageReceivedEventHandler))
}
WebMessageReceivedEventHandler(handler, ICoreWebView2, WebMessageReceivedEventArgs) {
	args := WebView2.WebMessageReceivedEventArgs(WebMessageReceivedEventArgs)
	msg := args.TryGetWebMessageAsString()
	MsgBox(msg)

}
It would appear to me, that you can probably use either method to transmit messages/data back and forth - just looking for some clear guidance on where one might be better than the other and vice versa?

Still loving this lib btw. Amazing efforts.

Thanks!

[EDIT] - Found this little topic, which i think answers most of my questions, or atleast some.
https://github.com/MicrosoftEdge/WebView2Feedback/issues/823

userXeo1
Posts: 39
Joined: 26 Feb 2020, 09:12

Re: 2.0-beta.1 - WebView2

Post by userXeo1 » 26 Feb 2023, 08:22

thqby wrote:
01 May 2022, 22:36

Code: Select all

class SyncHandler extends WebView2.Handler {
	__New(cb := 0) {
		this.obj := SyncHandler.CompletedEventHandler()
		this.obj.cb := cb
		super.__New(this.obj, 3)
	}
	wait() {
		o := this.obj
		while !o.status
			Sleep(10)
		o.status := 0, Sleep(100)
	}

	class CompletedEventHandler {
		status := 0, cb := 0
		call(handler, args*) {
			if this.cb
				(this.cb)(args)
			this.status := 1
		}
	}
}

g := Gui()
g.Show(Format("w{} h{}", A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
wv := WebView2.create(g.Hwnd)
nav_sync := SyncHandler()
exec_sync := SyncHandler((args) => OutputDebug(StrGet(args[2])))
wv.CoreWebView2.add_NavigationCompleted(nav_sync)
wv.CoreWebView2.Navigate("https://www.autohotkey.com")
nav_sync.wait()
wv.CoreWebView2.ExecuteScript(
	"document.querySelector('#menu-0 > div > div > div > div.mbr-navbar__column.mbr-navbar__menu > nav > div > ul > li:nth-child(2) > a').click()",
	exec_sync
)
exec_sync.wait()
wv.CoreWebView2.ExecuteScript(
	"document.querySelector('#head > div > div.h-tabs > ul > li:nth-child(3) > button').click()",
	exec_sync
)
exec_sync.wait()
wv.CoreWebView2.ExecuteScript(
	"document.querySelector('#left > div.tab.search.shrinked > div.input > input[type=search]').value='testing'",
	exec_sync
)
exec_sync.wait()
Any thoughts how to handle web pages that have auto-redirects,(URL1->URL2 ->URL3) besides setting sleep function to 10sec? What happens, the script will navigate to the url1, execute java script,(and log in) second page will redirect to 3rd URL. but scripts starts to execute JS prematurely on the second page. I am thinking of making a loop to check for element or some text, if it exists on page, if exists proceed, else sleep? I have no idea how to tackle this with WebView2.. Any Ideas? Code Sample? Thank you.

xroot
Posts: 40
Joined: 21 Jun 2019, 08:45

Re: WebView2

Post by xroot » 26 Feb 2023, 10:30

Tre4shunter, Here is my Neutron example, hope it might help.

Code: Select all

#Include lib\webview2.ahk

DocumentTitleChangedEventHandler(){
    iClick := wv.CoreWebView2.DocumentTitle
    Switch(iClick){
        Case 1,2: MsgBox "Button " iClick " Clicked","NewTron","Iconi t2"
    }
}

On_Key(iName,iKey){
    HostObj.iName := iName
    HostObj.iKey  := iKey
    wv.CoreWebView2.ExecuteScript(jsCode,0)
}

On_Exit(*){
    ExitApp    
}

I_Data(iData){
    MsgBox iData,"Form Data Return","iconi"
    Send "{Browser_Back}" 
}

NavStr := "
(
  <style>

    /*** Window Client Area ***/

    .main {
      /* Some settings for everything in the client area */
      font-size: 12pt;
      padding: 1em;
      overflow: auto;
    }

    .container {
      /* Only render items in the center 600px of the client area */
      max-width: 600px;
      margin: auto;
    }

    /*** Bootstrap Style Flexbox Utilities ***/

    .row {
      /* A row is basically just a flexbox container */
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }

    .w-50 {
      /* Fill almost half the row, leaving a bit of margin */
      width: 48%;
    }

    .w-100 {
      /* Fill the entire row */
      width: 100%;
    }

    @media screen and (max-width: 500px) {
      /* When the window gets shrunk */

      .w-50 {
        /* Reflow half-size elements to fill the entire row */
        width: 100%;
      }
    }

    /*** Generic Form Styling ***/

    input[type=text],
    input[type=email],
    input[type=number],
    input[type=password],
    select {
      width: 100%;
      padding: 0.75em;
      margin-bottom: 1em;

      border: 1px solid silver;
      border-radius: 0.35em;

      box-sizing: border-box;
    }

    label {
      display: inline-block;
      margin-bottom: 0.5em;
      font-weight: bold;
      font-size: 0.8em;
    }

    button {
      width: 100%;
      background-color: MediumSeaGreen;
      color: white;
      padding: 14px 20px;
      margin-bottom: 1em;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    input[type=submit]:hover {
      background-color: #45a049;
    }

    /* https://stackoverflow.com/a/17406564 */
    fieldset {
      margin-bottom: 1em;
      margin-top: 1.5em;
      border: 1px solid silver;
      border-radius: 0.35em;
      padding-top: 1em;
      box-sizing: border-box;
    }

    legend {
      background: white;
    }

    fieldset>legend {
      float: left;
      margin-top: -1.5em;
    }

    fieldset>legend+* {
      clear: both;
    }

    /*** Giant Key Styling ***/

    .keys {
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
    }

    .keys>div {
      width: 100px;
      height: 100px;
      margin: 10px;
      padding: 0;
      background: silver;
      text-align: center;
      font-size: 90px;
      color: white;
      border-radius: 1rem;
    }

    .keys>div.active {
      background: MediumSeaGreen;
    }

    /*** Table Styling ***/

    table {
      width: 100%;
      border-collapse: collapse;
      table-layout: fixed;
    }
    thead, tr:nth-child(even) {
      /* Color header and every other row */
      background: #eee;
    }
  </style>
<body>

  <!-- Main content area -->
  <div class="main">
    <div class="container">

      <h1>Welcome to Neutron</h1>
      <p>
        Neutron provides a powerful set of tools for build HTML-based user
        interfaces with AutoHotkey. It leverages the Trident engine, known for
        its use in Internet Explorer, because of its deep integration with the
        Microsoft Windows operating system and its wide availability across
        systems.
      </p>
      <p>
        This example, while named Simple, is not the most simplistic example.
        Instead, it is designed to demonstrate all of Neutron's built in behavior
        as a single custom page. It is meant to be simple by comparison to other
        examples like the Bootstrap example which demonstrate extending Neutron's
        functionality with third party web frameworks.
      </p>


      <!-- Example #1 -->

      <h2>Trigger AHK by page events</h2>
      <p>
        The simplest way of integrating a page to your script is by linking a
        button's click event to a function in your script. This can be easily
        achieved using the button's <code>onclick</code> attribute.
      </p>
      <div class="row">
        <button class="w-50" onclick="On_Click(1)">Button #1</button>
        <button class="w-50" onclick="On_Click(2)">Button #2</button>
      </div>
      <p>
        Click events aren't the only type that can be handled. The box below
        responds to mouse movement events and gets automatically updated with
        the cursor position by AutoHotkey.
      </p>
      <div style="border: 1px solid black; width: 100%; text-align: center; padding: 1em 0;"
        onmousemove="this.innerText='('+event.offsetX+', '+event.offsetY+')'" onmouseout="this.innerText='Mouse over this area!'">
        Mouse over this area!
      </div>

      <!-- Example #2 -->

      <h2>Update page by Hotkey</h2>
      <p>
        Try pressing the keys 1 through 4 on your keyboard!
      </p>
      <div class="keys">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
      </div>
      <p>
        This example demonstrates the following tasks:
      </p>
      <ul>
        <li>Limit a hotkey's activity to the Neutron window.</li>
        <li>Find a collection of elements using CSS selectors.</li>
        <li>Iterate over the collection with <code>Neutron.Each</code></li>
        <li>Update an element's CSS class string.</li>
      </ul>


      <!-- Example #3 -->

      <h2>Pass form data to AHK</h2>
      <p>
        This example shows how you would collect form data from Neutron.
      </p>
      <form onsubmit="iSubmit()">
        <div class="row">
          <div class="w-50">
            <label for="firstName">First Name</label>
            <input type="text" id="firstName" value="John" required>
          </div>
          <div class="w-50">
            <label for="lastName">Last Name</label>
            <input type="text" id="lastName" value="Smith" required>
          </div>
          <div class="w-100">
            <label for="email">Email</label>
            <input type="email" id="email" value="[email protected]">
          </div>
          <div class="w-100">
            <label for="password">Password</label>
            <input type="password" id="password" value="hunter2">
          </div>
          <div class="w-50">
            <label for="address">Address</label>
            <input type="text" id="address" value="123 Central Avenue">
          </div>
          <div class="w-50">
            <label for="address2">Address 2</label>
            <input type="text" id="address2" value="Apartment 42">
          </div>
          <div class="w-100">
            <label for="city">City</label>
            <input type="text" id="city" value="LEGO&reg; City">
          </div>
          <div class="w-50">
            <label for="state">State</label>
            <select id="state" required>
              <option value="Eat Me!" selected></option>
              <option>Confusion</option>
            </select>
          </div>
          <div class="w-50">
            <label for="zip">Zip</label>
            <input type="number" id="zip" value="1337">
          </div>
          <div class="w-100">
            <input type="checkbox" id="remember">
            <label for="remember">Remember me</label>
          </div>
        </div>
        <button type="submit">Submit</button>
      </form>
      <p>
        You can also use forms where there are multiple options for a value,
        such as by a set of checkboxes or multi-select. Radio selections work
        too!
      </p>

      <form onsubmit="iSubmit()">
        <fieldset>
          <legend>Favorite Foods</legend>
          <div class="row">
            <div class="w-50">
              <input type="checkbox" id="hamburgers" value="hamburgers" name="food">
              <label for="hamburgers">Hamburgers</label>
            </div>
            <div class="w-50">
              <input type="checkbox" id="hotdogs" value="hotdogs" name="food">
              <label for="hotdogs">Hot Dogs</label>
            </div>
            <div class="w-50">
              <input type="checkbox" id="fries" value="fries" name="food">
              <label for="fries">French Fries</label>
            </div>
            <div class="w-50">
              <input type="checkbox" id="cookies" value="cookies" name="food">
              <label for="cookies">Cookies</label>
            </div>
            <div class="w-50">
              <input type="checkbox" id="pizza" value="pizza" name="food">
              <label for="pizza">Pizza</label>
            </div>
            <div class="w-50">
              <input type="checkbox" id="chicken" value="chicken" name="food">
              <label for="chicken">Chicken</label>
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Favorite Languages</legend>
          <select id="favLangs" multiple style="border: none; padding: 0; margin: 0;">
            <option value="ahk">AutoHotkey</option>
            <option value="py">Python</option>
            <option value="rlx">Relax</option>
            <option value="cpp">C++</option>
          </select>
        </fieldset>
        <fieldset>
          <legend>Preferred Method of Contact</legend>
          <div class="row">
            <div class="w-50">
              <input type="radio" id="contactEmail" value="email" name="contact" checked>
              <label for="contactEmail">Email</label>
            </div>
            <div class="w-50">
              <input type="radio" id="contactPhone" value="phone" name="contact">
              <label for="contactPhone">Phone</label>
            </div>
            <div class="w-50">
              <input type="radio" id="contactEmail" value="email" name="contact">
              <label for="contactEmail">Snail Mail</label>
            </div>
            <div class="w-50">
              <input type="radio" id="contactIPoAC" value="IPoAC" name="contact">
              <label for="contactIPoAC">RFC 1149</label>
            </div>
          </div>
        </fieldset>
        <button type="submit">Submit</button>
      </form>


      <!-- Example #4 -->

      <h2>Dynamic Content Generation</h2>
      <p>
        Often you won't have the HTML you want on the page in advance, but
        instead need to generate it based on some data that the script receives,
        whether from a file, a web API, input boxes on the page, etc. Generating
        HTML on the fly is possible, but unless done right can introduce subtle
        bugs into your application.
      </p>
      <p>
        There are two main techniques to dynamic generation. First, you can
        write code that creates the HTML, then load that HTML onto the page by
        using something like <code>document.write(html);</code> or
        <code>element.innerHTML = html;</code>. Second, you can use DOM
        functions like <code>document.createElement</code> to generate the page
        elements directly without worrying about the HTML markup. This second
        option is usually the safer option, but is much more difficult to work
        with. Both techniques are demonstrated below.
      </p>

      <h3>HTML Generation</h3>
      <form onsubmit="iSubmit()">
        <div class="row">
          <div class="w-50">
            <label for="ex4_item1">Item</label>
            <input type="text" id="ex4_item1" value="Banana" required>
          </div>
          <div class="w-50">
            <label for="ex4_cost1">Cost ($)</label>
            <input type="number" id="ex4_cost1" value="3" required>
          </div>
        </div>
        <button type="submit">Submit</button>
      </form>
      <table id="ex4_table1">
        <thead>
          <tr>
            <th>Item</th>
            <th>Cost</th>
          </tr>
        </thead>
        <tbody></tbody>
      </table>

      <h3>DOM Generation</h3>
      <form onsubmit="iSubmit()">
        <div class="row">
          <div class="w-50">
            <label for="ex4_item2">Item</label>
            <input type="text" id="ex4_item2" value="Banana" required>
          </div>
          <div class="w-50">
            <label for="ex4_cost2">Cost ($)</label>
            <input type="number" id="ex4_cost2" value="3" required>
          </div>
        </div>
        <button type="submit">Submit</button>
      </form>
      <table id="ex4_table2">
        <thead>
          <tr>
            <th>Item</th>
            <th>Cost</th>
          </tr>
        </thead>
        <tbody></tbody>
      </table>

      <h1>Thanks for playing!</h1>
    </div> <!-- /container -->
  </div> <!-- /main -->
</body>
<script>
    const idiv = document.querySelectorAll(".keys > div");
    function On_Click(io){
        document.title = io;
        document.title = "";
    }
    function iSubmit(){
        history.back();
        var idata = "";
        var io = document.getElementsByTagName("input");
        for(let i=0;i<io.length;i++)
            idata += io[i].value + "\n";
        chrome.webview.hostObjects.AHK.getData(idata); 
    }
</script>
)"

jsCode := "
(
    (async function(){
        var iName = await chrome.webview.hostObjects.AHK.getHostProperty("iName");
        var ikey  = await chrome.webview.hostObjects.AHK.getHostProperty("iKey");
        idiv[iName].className = ikey;
    })();
)"

HostName := "AHK"
HostObj  := {iName:"",iKey:"",getData:I_Data}

win := Gui(,"WebView2 NewTron")
win.OnEvent "Close",On_Exit
win.Show "w800 h600"

wv := WebView2.create(win.hWnd)
wv.CoreWebView2.add_DocumentTitleChanged(WebView2.Handler(DocumentTitleChangedEventHandler))
wv.CoreWebView2.NavigateToString(NavStr)
wv.CoreWebView2.AddHostObjectToScript(HostName,HostObj)

#HotIf WinActive("ahk_id" win.hWnd)
    ~1::On_Key(0,"active")
    ~2::On_Key(1,"active")
    ~3::On_Key(2,"active")
    ~4::On_Key(3,"active")
    ~1 Up::On_Key(0,"")
    ~2 Up::On_Key(1,"")
    ~3 Up::On_Key(2,"")
    ~4 Up::On_Key(3,"")
#HotIf

Esc::ExitApp

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: WebView2

Post by kczx3 » 26 Feb 2023, 10:37

One way might be to only execute a script if the url match’s the end of the redirect since they usually have different hosts or subdomains.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: WebView2

Post by kczx3 » 26 Feb 2023, 10:46

Also, the NavigationStarting event mentions redirects having the same ID as the original navigation so maybe you could compare those? Although I doubt that works for JavaScript initiated redirects that a lot of authorization flows use these days.

tqphan
Posts: 26
Joined: 04 Mar 2019, 14:44

Re: WebView2

Post by tqphan » 23 Apr 2023, 21:14

@xroot Is there an alternative way to accomplish button click without using DocumentTitleChangedEventHandler? This seems like a hacky solution.

xroot
Posts: 40
Joined: 21 Jun 2019, 08:45

Re: WebView2

Post by xroot » 24 Apr 2023, 08:53

@tqphan yes there is, but, using doc title change event thinking who changes title of their page, I never have so this seemed to be a good solution.
You can use Host and Host Objects so javascript can respond back to AHK, something like "chrome.webview.hostObjects.AHK.iClick(io)".

tqphan
Posts: 26
Joined: 04 Mar 2019, 14:44

Re: WebView2

Post by tqphan » 29 Apr 2023, 17:32

How do I make

Code: Select all

WinSetTransColor "000111", "ahk_id " win.hWnd
work with WebView2? I'm displaying a page with #000111 background and I want the #000111 color to be transparent.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: WebView2

Post by kczx3 » 29 Apr 2023, 18:59


tqphan
Posts: 26
Joined: 04 Mar 2019, 14:44

Re: WebView2

Post by tqphan » 29 Apr 2023, 19:46

What is AHK equivalent of System.Drawing.Color.Transparent?

I tried

Code: Select all

wv.DefaultBackgroundColor := 0x00000111

Post Reply

Return to “Scripts and Functions (v2)”