使い方②をWebView2で記述してみましょう。
新しいECMAScriptの文法が利用できますので、より、スマートな記述が可能です。
jsmode "WebView2\\" + currentmacrofilename; execjs macrodir + @"\HmPunyHttpServer\HmPunyHttpServer.js"; js{ var server; // 初期化しないこと。マクロ実行空間を超えて維持する必要があるので、varで。 server?.close(); server = createPunyHttpServer({rootFolder:"C:\\あいうえお"}); server?.startAsync(openBrowserPane); function openBrowserPane(port) { if (!port) { // サーバー構築に失敗 return; } let url = `http://localhost:${port}/index.html`; browserpanecommand( { target: "_each", url: url, show: 1, size: 500, initialize: "async" }); } } // js
このマクロを実行すると、C:\あいうえお がドキュメントルートになります。
そして、ブラウザが起動して、http://localhost:ポート番号/index.html が表示されます。