thqby / ahk2_lib

MIT License
233 stars 32 forks source link

WebView2 support local files? #57

Closed Banaanae closed 3 months ago

Banaanae commented 3 months ago

Might be using it wrong, but I'm getting an error while attempting to use monaco editor inside the WebView2 lib

AHK Code (Just the example code from README):

#Include <WebView2\WebView2>

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('./Monaco-Editor.html')
wv.AddHostObjectToScript('ahk', {str:'str from ahk',func:MsgBox})
wv.OpenDevToolsWindow()

HTML Code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs/loader.js"></script>
    </head>
    <body>
    <div id="editor" style="height: 500px;"></div>
        <script>
            require.config({ paths: { 'vs': 'https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs' }});
            require(['vs/editor/editor.main'], function() {
                var editor = monaco.editor.create(document.getElementById('editor'), {
                    value: 'console.log("Hello, World!");',
                    language: 'javascript',
                    theme: 'vs-dark'
                });
            });
        </script>
    </body>
</html>

It didn't work with a basic hello world html file either

Error: image

Banaanae commented 3 months ago

Just needed to specifiy absolute path