thqby / ahk2_lib

MIT License
222 stars 31 forks source link

Using WebView2 to open local html-page #59

Closed hoppfrosch closed 1 month ago

hoppfrosch commented 1 month ago

Using <WebView2/WebView2> to open a local html page leads to following error:

Error: (0x80070057) Wrong Parameter.

    ---- WebView2\WebView2.ahk
    434: }
    435: {
▶   435: Return ComCall(5, this, 'wstr', uri)
    435: }
    436: {

The current thread will exit.

Call stack:
WebView2\WebView2.ahk (435) : [ComCall] Return ComCall(5, this, 'wstr', uri)
WebView2\WebView2.ahk (435) : [WebView2.Core.Prototype.Navigate] Return ComCall(5, this, 'wstr', uri)
WebView2\test01.ahk (9) : [] wv.Navigate('test01.html')

Here are the contents of my AHK-File test01.ahk:

#Include "WebView2.ahk"

main := Gui('+Resize')
main.OnEvent('Close', (*) => (wvc := wv := 0))
main.Show(Format('w{} h{}', A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))

wvc := WebView2.create(main.Hwnd)
wv := wvc.CoreWebView2
wv.Navigate('test01.html')

and here is my html file test01.hml:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Page with close button</title>
</head>
<body>
    <p>Simple Page.</p>
    <button onclick="closePage()">OK</button>

    <script>
        function closePage() {
            window.close();
        }
    </script>
</body>
</html>
hoppfrosch commented 1 month ago

Argl ... should have researched first ...

I should have used a correct URI for the local file:

wv.Navigate('file:///' A_ScriptDir '\test01.html')