WebView2
Re: WebView2
@idkwhattowrite
Yes, you can open local html files, just use the URI: file:///
E.G.:
file:///C:/.../index.html
Yes, you can open local html files, just use the URI: file:///
E.G.:
file:///C:/.../index.html
Re: WebView2
Why don't you try it first?
I have not had this issue. You also did not provide code to reproduce the issue.
Also, this issue has been mentioned in previous posts. I gave a solution based on that situation, and guessed that your situation was similar to that one.
Re: WebView2
@leuhmanu
Code: Select all
wvc := WebView2.CreateControllerAsync(main.Hwnd,, A_ScriptDir "\data\1" ).await2()
wv := wvc.CoreWebView2
wv.Profile.IsPasswordAutosaveEnabled := true
wv.Profile.IsGeneralAutofillEnabled := true
-
- Posts: 13
- Joined: 30 Oct 2024, 03:12
- Contact:
Re: WebView2
And is there a way to open index file from the same directory?
I mean ahk file and index file are in one directory, is there an easy wasy? Because if i move this directory, for example: From Folder1 to Folder2, i will need to write new URL.
Re: WebView2
@idkwhattowrite
If you have your html file on the same directory as the script, you can do this:
If you have your html file on the same directory as the script, you can do this:
Code: Select all
wv.Navigate("file:///" A_ScriptDir "\index.html")
-
- Posts: 13
- Joined: 30 Oct 2024, 03:12
- Contact:
Re: WebView2
TYZeroWidth wrote: ↑01 Nov 2024, 00:30@idkwhattowrite
If you have your html file on the same directory as the script, you can do this:Code: Select all
wv.Navigate("file:///" A_ScriptDir "\index.html")
Re: WebView2
I noticed a couple people mention printing to pdf problems and I read through every reply. I didn't see any answers to those questions and I'm wondering if this is still a problem?
Re: WebView2
Which problem are you concerned about? Printing to PDF is capable on my end. I know one user had some issues with scaling, but it's hard to say what may have been causing that particular issue as I assume it could be a number of things.
You can reach me quickest in the AutoHotkey Discord
WebViewToo -- Easy Web-based GUIs using WebView2
WebViewToo -- Easy Web-based GUIs using WebView2
Re: WebView2
@thqby, back on August 16th, you pushed an update for the library (upgrate to 1.0.2651.64 => Commit 39861f3) in which you removed the __Enum(n) method from the class Base and then added a new class List. I'm trying to figure out how to make use of this new class to iterate through properties that I had previously been able to do and I'm not having much luck. The furthest I've gotten with the new class is encountering the following error: Error: This value of type "WebView2.List" has no property named "Count". Could you provide an example of how to get a list of property values for things such as the wv.Settings
I did test adding back in the removed method, and the iteration works and does not seem to cause any issues. Below is the code that I had been using prior to this update to get output for properties.
I did test adding back in the removed method, and the iteration works and does not seem to cause any issues. Below is the code that I had been using prior to this update to get output for properties.
Code: Select all
MsgBox(ForEach(wv.Settings, "wv.Settings"))
ForEach(Obj, Parent := "Default") {
Output := ""
try {
for Key, Value in Obj {
try {
Output .= Parent " >> " Key ": " Value "`n"
} catch {
Output .= ForEach(Value, Parent " >> " Key)
}
}
}
return Trim(Output, "`n")
}
You can reach me quickest in the AutoHotkey Discord
WebViewToo -- Easy Web-based GUIs using WebView2
WebViewToo -- Easy Web-based GUIs using WebView2
Re: WebView2
Is this for debugging? The debugger can output objects directly. In addition, in v2.1, you can also enumerate the properties of the base class through for k, v in obj.Props().
Subclasses of WebView2.List can be enumerated by for item in list.
Code: Select all
base_props(obj) {
iter := obj.Base.OwnProps(), iter() ; skip `__Class`
return next
next(&k, &v, *) {
while iter(&k)
try if !((v := obj.%k%) is Func)
return true
return false
}
}
for k, v in base_props(Map()) {
msgbox k ' ' v
}
Re: WebView2
Nice work thqby
Question: Did you implement access to Windows COM objects ( which has a jscript interface )
So i can do something similar to:
var shell = ActiveXObject("WScript.Shell"); etc etc..
To refactor that functionality with a WebView2 in a C# .NET App is done like this:
Question: Did you implement access to Windows COM objects ( which has a jscript interface )
So i can do something similar to:
var shell = ActiveXObject("WScript.Shell"); etc etc..
To refactor that functionality with a WebView2 in a C# .NET App is done like this:
Code: Select all
// method belongs to the object you add with AddHostObjectToScript
public Object NewActiveXObject(String progId)
{
return (Activator.CreateInstance(Type.GetTypeFromProgID(progId)));
}
Re: WebView2
@squadjot
I don't know what you mean. Do you mean add comobject as a host object to webview2? That should be supported.
I don't know what you mean. Do you mean add comobject as a host object to webview2? That should be supported.
Re: WebView2
I mean so i can replicate the functionailty of for an example:
Code: Select all
var fso = new ActiveXObject("Scripting.FileSystem");
Re: WebView2
By adding the ComObject class of ahk to webview2, you can create other com objects by calling it.
See Example 1
See Example 1
Re: WebView2
Hi thqby
I am new to AHK script but I got it working! Very nice
Would you mind showing me how to use "AllowExternalDrop"?
My goal is; To be able register drag drop of files from within the webview/js
My first thought was to have a secondary (hidden/transparent) gui that would work as dedicated "droparea"
I would show/hide and set pos/size of the droparea from js, and when files were dropped, i would feed the paths in to the webview with executescript or postmessage.
The solution above actually works okay, but i'm wondering if this is a unnecessary "hack" and if there's a cleaner way to do this?
I am new to AHK script but I got it working! Very nice
Would you mind showing me how to use "AllowExternalDrop"?
My goal is; To be able register drag drop of files from within the webview/js
My first thought was to have a secondary (hidden/transparent) gui that would work as dedicated "droparea"
I would show/hide and set pos/size of the droparea from js, and when files were dropped, i would feed the paths in to the webview with executescript or postmessage.
The solution above actually works okay, but i'm wondering if this is a unnecessary "hack" and if there's a cleaner way to do this?
Re: WebView2
Code: Select all
#Include <WebView2\WebView2>
g := Gui()
g.Show('w800 h600')
wv := WebView2.CreateControllerAsync(g.Hwnd).await2()
wv.CoreWebView2.add_WebMessageReceived(handler)
handler(wv, args) {
if args.TryGetWebMessageAsString() == 'drop' {
paths := ''
for obj in args.additionalObjects {
try {
obj := obj.as(WebView2.File)
paths .= obj.Path '`n'
}
}
ToolTip(paths)
}
}
wv.CoreWebView2.NavigateToString('
(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 800px;
height: 600px;
border-radius: 5px;
background-color: #ccc;
font-size: 18px;
font-weight: bold;
color: #fff;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div class="box">drag the files here</div>
<script>
let box = document.querySelector('.box');
box.ondragover = function (ev) {
ev.preventDefault();
ev.stopPropagation();
return false;
}
box.ondrop = function (ev) {
ev.preventDefault();
ev.stopPropagation();
chrome.webview.postMessageWithAdditionalObjects('drop', ev.dataTransfer.files);
return false;
}
</script>
</body>
</html>
)')
Last edited by thqby on 02 Dec 2024, 20:46, edited 1 time in total.
Re: WebView2
Thanks, but it doesn't seem to give my filepaths, only filenames.thqby wrote: ↑02 Dec 2024, 07:58Implemented through html, this is an example I found on the Internet.Code: Select all
#Include <WebView2\WebView2> g := Gui() g.Show('w800 h600') wv := WebView2.CreateControllerAsync(g.Hwnd).await2() wv.CoreWebView2.OpenDevToolsWindow() wv.CoreWebView2.NavigateToString(' ( <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { margin: 0; padding: 0; } .box { width: 800px; height: 600px; border-radius: 5px; background-color: #ccc; font-size: 18px; font-weight: bold; color: #fff; text-align: center; line-height: 100px; } </style> </head> <body> <div class="box">drag the files here</div> <script> let box = document.querySelector('.box'); box.ondragover = function (ev) { ev.preventDefault(); ev.stopPropagation(); return false; } box.ondrop = function (ev) { ev.preventDefault(); ev.stopPropagation(); console.dir(ev.dataTransfer.files); return false; } </script> </body> </html> )')
Re: WebView2
Hmm, seems like full paths is something that has been on the wish list for some time. If i read correctly it might be included in recent WebView2 update
https://github.com/MicrosoftEdge/WebView2Feedback/issues/501
https://github.com/MicrosoftEdge/WebView2Feedback/issues/501
Re: WebView2
@squadjot
I have updated WebView2.ahk and the above code.
The path can be obtained from the File object on the host side.
I have updated WebView2.ahk and the above code.
The path can be obtained from the File object on the host side.