-
Jan 27th, 2023, 03:54 AM
#241
Addicted Member
Re: VB6 WebView2-Binding (Edge-Chromium)
excellent
I always use your tool (vbRichClient) , thank you for your hard work
WebView2 is a very good idea
The only problem is that I don't have permission to access and read files from the hard drive (allow file)
For example
In web page and javascript
HTML Code:
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<script type="text/javascript">
video.load('Fire.mp4');
</script>
</body>
</html>
Error, this page says I receive
-
Jan 27th, 2023, 09:15 AM
#242
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Mojtaba
excellent
...don't have permission to access and read files from the hard drive...
The code below works for me (playing a local *.mp4 file):
Code:
Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Load()
Dim VideoFile As String, sHTML As String, HtmlFile As String
VideoFile = "c:\temp\test.mp4"
HtmlFile = New_c.FSO.GetLocalAppDataPath & "\temp_vidplayer.html"
sHTML = "<!DOCTYPE html><html><head><meta http-equiv='X-UA-Compatible' content='IE=edge'></head>" & _
"<body><video controls width='100%' height='auto' src='" & VideoFile & "'/></body></html>"
New_c.FSO.WriteTextContent HtmlFile, sHTML, True
Me.Visible = True 'ensure Visibility before the Bind-call
Set WV = New_c.WebView2(Me.hWnd)
WV.Navigate HtmlFile
End Sub
Private Sub Form_Resize()
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Olaf
-
Jan 28th, 2023, 03:33 AM
#243
Lively Member
Re: VB6 WebView2-Binding (Edge-Chromium)
hello Olaf
have you had time to investigate the issue with the latest fixed versions of webview2?
Thanks in advance
Best regards
François
-
Jan 28th, 2023, 11:30 AM
#244
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by saturnian
...have you had time to investigate the issue with the latest fixed versions of webview2?
Yes, have done that just now ...
and I'm not able to reproduce the problems (here on a Win10 with all Updates).
Used the following relevant code-lines.
Code:
P = "c:\temp\Microsoft.WebView2.FixedVersionRuntime.109.0.1518.70.x86"
If WV.BindTo(picWV.hWnd, 8, P, "c:\temp\WV2UserData") = 0 Then
MsgBox "couldn't initialize WebView-Binding": Exit Sub
End If
Like you, I've used an explicitly given "fixed-runtime-path" as well as a "local UserData-Path"...
What I took care of was the following:
- I've downloaded the x86-flagged, fixed runtime from the MS-site (it comes in a *.cab-file)
- FWIW, I've unpacked this *.cab with 7zip (and not the built-in Win10-CabViewer)
- placed the unpacked Folder in a Parent-Folder I have full write-rights on ("c:\temp\...")
- created a new, empty UserDirectory in "c:\temp\WV2UserData" (before trying the Bind-call)
Things to note (things of importance, regarding the error on your side):
- already mentioned, but make sure to use the 32bit-(x86)version of the fixed-runtime
- my "User-Directory" is not a sub-directory of the "fixed-runtime-folder"
- neither Directory is causing "potential File-Virtualization-issues" (due to placement in the C:\Programs\-Folder)
- neither Directory is provocing "treatment as an x64-Program" (due to placement in the C:\Programs\-Folder)
- Me.Caption = New_c.Version ...shows "6.0.12" (just make sure to report this "live", to rule out regfree-loading of older versions)
HTH
Olaf
-
Jan 29th, 2023, 09:52 AM
#245
Lively Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Schmidt
What I took care of was the following:
- I've downloaded the x86-flagged, fixed runtime from the MS-site (it comes in a *.cab-file)
- FWIW, I've unpacked this *.cab with 7zip (and not the built-in Win10-CabViewer)
- placed the unpacked Folder in a Parent-Folder I have full write-rights on ("c:\temp\...")
- created a new, empty UserDirectory in "c:\temp\WV2UserData" (before trying the Bind-call)
Things to note (things of importance, regarding the error on your side):
- already mentioned, but make sure to use the 32bit-(x86)version of the fixed-runtime
- my "User-Directory" is not a sub-directory of the "fixed-runtime-folder"
- neither Directory is causing "potential File-Virtualization-issues" (due to placement in the C:\Programs\-Folder)
- neither Directory is provocing "treatment as an x64-Program" (due to placement in the C:\Programs\-Folder)
- Me.Caption = New_c.Version ...shows "6.0.12" (just make sure to report this "live", to rule out regfree-loading of older versions)
HTH
Olaf
I checked all the previous items except:
Me.Caption = New_c.Version ...shows... ... ... "6.0.10" !
Because, on the site http://vbrichclient.com/ it is displayed:
Downloads
The Base-Dlls of the current toolset (version 6) are contained in this minimum-package:
RC6BaseDlls.zip (~ 3.5MB, current version: 6.0.10, last updated: 2022-07-31 ... including SQLite-version: 3.39.2)
so I didn't think to download RC6BaseDlls.zip again ! I remained convinced that the current version was 6.0.10 !
I won't be fooled now !
Version 6.0.12 fixes all issues ! Thanks
François
-
Feb 24th, 2023, 10:53 AM
#246
New Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi have nice day thanks for this complemente,
i have a simple question
i am try navigate to http://jsfiddle.net/qqzxtk67/
this fire new window
How i can manipulate this thanks?
-
Feb 25th, 2023, 06:26 AM
#247
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by astronald
Not sure, what you mean exactly (with "manipulate this")...
What do you want to achieve in the end?
Olaf
-
Feb 25th, 2023, 02:48 PM
#248
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Can your control make use of OnFrameLoad event?
I need to inject JS at this point of time.
Last edited by tmighty2; Feb 25th, 2023 at 02:53 PM.
-
Feb 26th, 2023, 12:14 AM
#249
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
Can your control make use of OnFrameLoad event?
I need to inject JS at this point of time.
Have not played around with iFrames so far (in the context of WV2 and the stuff i use it for currently) -
but the documentation says (about the AddScriptToExecuteOnDocumentCreated-method):
The injected script will apply to all future top level document and child frame navigations...
With that, you should be able to place dedicated js-functions and -variables (for use from within an iFrame),
without the need of "waiting for a FrameLoad-event".
If you're already using AddScriptToExecuteOnDocumentCreated -
can you post a short example, what you want to achieve - and where the problem comes in?
Olaf
-
Feb 26th, 2023, 05:07 PM
#250
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I need to inject scripts to change the pages colors for handicapped users, and this is the only event where I can do it.
-
Feb 26th, 2023, 08:00 PM
#251
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
I need to inject scripts to change the pages colors for handicapped users, and this is the only event where I can do it.
I'm quite sure, that AddScriptToExecuteOnDocumentCreated can accomplish what you want
(without using that event).
Please post some code-example.
Olaf
-
Feb 27th, 2023, 09:06 AM
#252
Addicted Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Dear Olaf,
First of all, as written by me quite a few times in our forums in the past, I remain in awe of both your fabulous work and your fabulous heart. I am happy that I finally got time to dig into your vbRichClient-Framework, learning many aspects of it, slowly and steadily, since the past 2-3 weeks.
Thanks a TON to you, I learnt the "fundamentals" of 'Open Source' licenses for the first time, from your '_Library-Licenses.txt' file. My Hearty Thanks in TONs, time and again, to you and all the developers of all the "Open Source" libraries/tools.
Just thought of letting you know that some of the links (to the 'Open Source' libraries) in the aforesaid text file are not working now. For e.g., for LZ4, "http://cyan4973.github.io/lz4/" does not work now. As far as I have explored, "https://github.com/lz4/lz4" looks to be the correct page now. Similarly, "https://zlib.net/zlib_license.html" works for the latest license page of 'zlib' (and not http://www.gzip.org/zlib/zlib_license.html). You may anyway double-check on this from your side too because I am quite new to using "Open Source" libraries. I just felt that I should let you know my findings so that you can replace the non-working links with the right ones in the '_Library-Licenses.txt' file in the next release of vbRichClient-Framework, if at all my findings are correct. If my findings are not correct, kindly bear with me.
Well, the WebView2Loader.dll found in your latest "RC6BaseDlls.zip" package is 112KB (115, 128 bytes) with version number of 1.0.1462.37.
Specifically, with respect to the deployment of one's compiled application in a different system
--
Should I always use this '1.0.1462.37' version numbered WebView2Loader.dll only? (Presuming your cWebView2 makes calls specific to this DLL only)
(OR)
Can I use the latest WebView2Loader.dll also? The version number of the latest WebView2Loader.dll is "1.0.1587.40" as of today, as per https://www.nuget.org/packages/Microsoft.Web.WebView2, if I am right.
(OR)
Should I always use the latest WebView2Loader.dll only?
--
Thanks in TONs once again. I sometimes go silent thinking of the immense magnitude/depth of your work for this world society. God Bless you, olaf! God Bless All!
Kind Regards.
-
Feb 28th, 2023, 10:55 AM
#253
Addicted Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Dear Olaf,
I noticed in https://www.cairographics.org/news/ that a new release of Cairo library has happened after quite a long gap of time. This news got me really excited thinking that this would mean that "perhaps" you have now started working on releasing the next RC6 build covering all the new features of Cairo library. If so, then my wishes in advance to you for the new/updated release of RC6.
Kind Regards.
-
Feb 28th, 2023, 11:10 AM
#254
Addicted Member
Re: VB6 WebView2-Binding (Edge-Chromium)
And, while I await with patience your answer to my query regarding 'WebView2Loader.dll' in post no. 252, dear Olaf,
Coming to 'Cairo', I have a small query. How to include blur also to a text with shadow? For instance, in CSS, the 'text-shadow' property has 'blur radius' too (ref: https://developer.mozilla.org/en-US/...SS/text-shadow)
I understood by reading some materials in the net that Cairo does not provide the 'blur' feature on text shadows straightaway but it can be achieved by writing a suitable routine in c++. I am not comfortable in c++ coding though.
I do remember reading (a week back or so) about 'Gaussian blur' in your 'Cairo' tutorials AND/OR in some of your forum messages but I saw 'Gaussian blur' applied to images only, if my understanding was right.
Honestly, I have not found time yet to go through all your excellent 'Cairo' tutorials. But, I do have "sincerely" gone through some of them and learnt a good lot about text rendering on paths. If indeed 'blur on text shadow' is already covered by you in any of your tutorials OR in any of your forum messages, then kindly intimate me the same and I shall go through them. Or, if such tutorials/messages do not exist yet, then, if at all and when your time permits, kindly provide me a code snippet which would "exactly" mimic what the following CSS would achieve when applied for any text.
--
"text-shadow: h-offset v-offset blur-radius color;"
--
I take this opportunity to once again thank you for both your work and your heart. God Bless you! God Bless ALL!
Kind Regards.
-
Feb 28th, 2023, 02:30 PM
#255
New Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Schmidt
Not sure, what you mean exactly (with "manipulate this")...
What do you want to achieve in the end?
Olaf
Thanks i want Execute javascript on new windows and read elements
-
Mar 1st, 2023, 06:41 AM
#256
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by softv
Can I use the latest WebView2Loader.dll also?
You can, but you don't have to...
WebView2Loader.dll is just a small "communication-vehicle" between your App -
and the "rolling, evergreen" Edge/Chromium-releases MS performs under the covers of your OS automatically.
If there's a new feature I expose in new RC6.cWebView2-releases
(using potentially "new, extended communication-interfaces" of the WebView2Loader),
then I'll deliver the RC6-bundle with that new(er) WebView2Loader.dll as well, of course.
Thanks for the FOSS-Link-updates - I've included them now in _LibraryLicenses.txt.
As for "plain cairo-questions" ... it's better to ask them in the normal Forum in the future -
(to keep this thread here related to the RC6.cWebView2-class and its usage).
But here's a little helper-function for "shadowed text-output":
Code:
Option Explicit
Private Sub Form_Load()
Dim CC As cCairoContext
Set CC = Cairo.CreateSurface(800, 600).CreateContext 'create the "main"-Surface-context
CC.Paint 1, Cairo.CreateSolidPatternLng(&H333333) 'ensures a dark-grey background
CC.SelectFont "Times New Roman", 22, vbGreen, False, True
DrawTextWithShadowOn CC, 10, 10, 300, 50, "Some shadowed Text", 4, vbYellow, 1, 1
Set Picture = CC.Surface.Picture
End Sub
Sub DrawTextWithShadowOn(CC As cCairoContext, x, y, dx, dy, Text As String, _
Optional ByVal R& = 3, Optional ByVal ShadowColor&, Optional ByVal xOffs#, Optional ByVal yOffs#)
CC.Save
CC.TranslateDrawings x, y
CC.PushGroup CAIRO_CONTENT_COLOR_ALPHA, 0, 0, dx, dy
CC.DrawText 0, 0, dx, dy, Text, True 'render the text within a Push/Pop-sequence
Dim Pat As cCairoPattern: Set Pat = CC.PopGroup(True) 'retrieve the output via Pop (in a Pattern-Obj)
With Cairo.CreateSurface(dx, dy).CreateContext 'create a temp-surface in the dimensions of the Text-Rect
.Paint 1, Pat '"play back" the pattern from the above "Push/Pop-Operation" on this temp-Surface
'and what follows now, is simply two calls (1. rendering the blurred-temp-surface, and 2. rendering the unblurred srf on top)
CC.RenderSurfaceContent .Surface.GaussianBlur(R / 2, R, True, ShadowColor), xOffs - R, yOffs - R
CC.RenderSurfaceContent .Surface, 0, 0
End With
CC.Restore
End Sub
As for upgrading to new(er) Cairo-Releases... the current Cairo.Version 1.17.02
(which includes some "cherry-picks" from later releases),
it seems to work nicely and stable (without mem-leaks) - so unless there's some new features which are a "must have",
I'm not planning on updating to later versions anytime soon.
Olaf
Last edited by Schmidt; Mar 1st, 2023 at 07:01 AM.
-
Mar 1st, 2023, 08:34 AM
#257
Addicted Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Schmidt
You can, but you don't have to...
... .. .
But here's a little helper-function for "shadowed text-output":
.. .. .
Olaf
Thanks a LOT, Olaf. As ever, you are so helpful with all the detailed information regarding WebView2Loader.dll, etc.
The helper function worked like a charm to create "text shadows with blur"! The best way to see its beauty in action was to change the various parameters (color, offsets, etc.) and see the corresponding effects. It was wonderful. Really. I will now try to take time to understand more of Gaussian Blur.
And, I am really sorry about posting my cairo-related query in this "RC6 cWebView2"-related thread. Only 5 minutes after posting it, I suddenly realised my mistake. I will be careful in the future. Sorry again.
Kindest Regards.
-
Mar 4th, 2023, 03:48 AM
#258
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I have uploaded the script here:
https://drive.google.com/file/d/1ovs...ew?usp=sharing
When you inject the entire text and then navigate to web.whatsapp.com, the selected chat will be blue.
That is how you can test if it worked.
Thank you!
-
Mar 4th, 2023, 06:36 AM
#259
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I have tried it like this:
Code:
Private Sub Form_Load()
Visible = True '<- it's important, that the hosting TopLevel-Form is visible...
'...(and thus the Child-PicBox indirectly as well) - before we Bind the PicBox to the WebView
Set WV = New_c.WebView2 'create the instance
If WV.BindTo(picWV.hWnd) = 0 Then MsgBox "couldn't initialize WebView-Binding": Exit Sub
' Set WV = New_c.WebView2(picWV.hWnd) 'create the instance
' If WV Is Nothing Then MsgBox "couldn't initialize WebView-Binding": Exit Sub
LocalWebViewInit 'initialize the WebView for local usage here in our Form
Dim sWA$
sWA = GetText("c:\users\myuser\desktop\whatsapp.txt")
WV.AddScriptToExecuteOnDocumentCreated sWA
End Sub
Private Sub cmdNavigate_Click()
WV.Navigate "https://web.whatsapp.com"
End Sub
Private Function GetText(ByVal u As String) As String
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim strm As Scripting.TextStream
With fso
Set strm = .OpenTextFile(u, ForReading, False, TristateTrue)
Do Until strm.AtEndOfStream
GetText = strm.ReadAll
Loop
strm.Close
End With
strm.Close
End Function
But that doesn't work. The chat should highlighted with blue color, but it's not.
Also, calling the JS functions that I added does not work.
Last edited by tmighty2; Mar 4th, 2023 at 06:42 AM.
-
Mar 4th, 2023, 08:18 AM
#260
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
...calling the JS functions that I added does not work.
There is an error in your larger js-Code-File:
Code:
const setupWhatsapp = () => {
alert('before highlighter');
highlighter.initHighlighting();
alert('after highlighter); // <- missing string-quote-char
overrideSelectedItemBackgroundColor(); // <- therefore, this line will not execute
};
BTW, do you get any of the "other alerts" you've placed there?
You could also place this little EventHandler-snippet via AddScriptOnDocumentCreated (in case you know the iFrame-ID):
Code:
document.getElementById('my_iframe_id').onload = function() {
// load your extra-modules (including your inits and color-replacements) here
}
Cannot further play around with this myself, because I have no "whatsapp"-account.
Olaf
-
Mar 4th, 2023, 09:41 AM
#261
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by astronald
...i want Execute javascript on new windows and read elements
Not sure, whether the following example does what you had in mind -
but the demo below will suppress the "WV2-built-in default-BrowserWindow-Popups",
and will simply create additional VB-Form-instances instead (each using their own internal WV-Instance of course).
Code:
Option Explicit
Public WithEvents WV As cWebView2, WithEvents tmrNewWindow As cTimer
Private Sub Form_Load()
Me.Visible = True 'ensure Visibility before the Bind-call
Set WV = New_c.WebView2(Me.hWnd) 'does an implicit bind-call (within this constructor-method)
WV.AddScriptToExecuteOnDocumentCreated "function openPopup(uri){window.open(uri,'','width=800,height=600')}"
If Forms.Count = 1 Then 'it's the first instance of this Form-Type (so we show an entry-demo-page, based on our own html-text)
Const btnDef$ = "<input value='show new window' type='button' on" & "click='openPopup(""https://google.com"")'>"
WV.NavigateToString btnDef
End If
WV.SyncSizeToHostWindow
End Sub
Private Sub Form_Resize()
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Private Sub WV_NewWindowRequested(ByVal IsUserInitiated As Boolean, IsHandled As Boolean, ByVal URI As String, NewWindowFeatures As RC6.cCollection)
IsHandled = True '<- suppress the Browser-Controls default-handler
NewWindowFeatures.Prop("URI") = URI 'let's enhance the features-(JSON)collection about the URI-Property
Set tmrNewWindow = New_c.Timer(10, True, NewWindowFeatures) 'and now buffer the features-(JSON)collection in the timer-tag, to be able to leave here as soon as possible for the sake of "non-blocking"
End Sub
Private Sub tmrNewWindow_Timer() 'this decoupling oneshot-timer only fires in case of a new Window-Request
ShowNewWindow tmrNewWindow.Tag 'pass the JSON-collection along (from the timers Variant-Typed Tag-Property)
End Sub
Public Sub ShowNewWindow(NewWindowFeatures As cCollection)
Set tmrNewWindow = Nothing 'we can safely destroy the "one-shot"-timerInstance now (since it delivered its Tag-Data)
Dim F As New Form1
F.Show , Me 'let's show the new form (after setting its feature-Collection above)
With NewWindowFeatures
If .Prop("HasPosition") Then F.Move .Prop("Left") * Screen.TwipsPerPixelX, _
.Prop("Top") * Screen.TwipsPerPixelY
If .Prop("HasSize") Then F.Move F.Left, F.Top, .Prop("Width") * Screen.TwipsPerPixelX, _
.Prop("Height") * Screen.TwipsPerPixelY
F.Caption = .Prop("URI")
F.WV.Navigate .Prop("URI")
Debug.Print .SerializeToJSONString '(just to show, what else is contained in the features-collection)
End With
End Sub
HTH
Olaf
-
Mar 4th, 2023, 01:39 PM
#262
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Last edited by tmighty2; Mar 4th, 2023 at 01:43 PM.
-
Mar 4th, 2023, 05:28 PM
#263
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
How could I call this js function using WV2?
Dim c As cStringBuilder
Set c = New cStringBuilder
c.Append "function GetScrollPosX()"
c.Append "{"
c.Append " return (Math.max(document.body.scrollLeft,document.documentElement.scrollLeft));"
c.Append "}"
-
Mar 4th, 2023, 05:30 PM
#264
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
And I have to say Congralatutions and thank you. I use your dhRichClient in all my apps. I could not live without it. And I hate .NET. The IDE is so slow that I just can't use it. Really, I need 5x as much time just because it responds so slowly and has such bad Edit and Continue capabilities. I am so much quicker with VB6. I use .NET for simpler projects only or for Unity which itself is slow to work with. But for quick typing, nothing is better than VB6.
-
Mar 4th, 2023, 08:22 PM
#265
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
How could I call this js function using WV2?
Dim c As cStringBuilder
Set c = New cStringBuilder
c.Append "function GetScrollPosX()"
c.Append "{"
c.Append " return (Math.max(document.body.scrollLeft,document.documentElement.scrollLeft));"
c.Append "}"
I'd use the StringBuilder via New_c constructor (for better "regfree-mode-compatibility"):
Code:
With New_c.StringBuilder
.AddNL "function GetScrollPosX(){"
.AddNL " return Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)"
.AddNL "}"
WV.AddScriptToExecuteOnDocumentCreated .ToString
End With
So, the adding of this function-code-snippet happens in the line before the "End With"-destruction of the StringBuilder.
The functioin-call itself can then be done from the VB6-side by specifying the funcName (without parens) in WV.jsRun:
Debug.Print WV.jsRun("GetScrollPosX") 'optional Parameter-Passing via ParamArray is possible
And JFTR, also "pure-property-access" is possible, without any "extra-function-definition" -
(even for "nested-props", as long as there's "only dots and no parentheses" in the prop-hierarchy-string):
Debug.Print WV.jsProp("document.body.scrollLeft")
Olaf
-
Mar 4th, 2023, 09:10 PM
#266
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
How do I get the currently shown URL, please?
-
Mar 4th, 2023, 09:47 PM
#267
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Is there perhaps a way to include an ad blocker?
-
Mar 4th, 2023, 10:07 PM
#268
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I am trying to run this JS code to scroll the window down:
WV.jsRunAsync "window.scrollBy({ top: 300, behavior: "smooth" });"
It does not work. What am I doing wrong?
-
Mar 5th, 2023, 01:02 PM
#269
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
WV.jsRunAsync "window.scrollBy({ top: 300, behavior: "smooth" });"
It does not work. What am I doing wrong?
What you're doing wrong is, to not read the Parameter-Names in the Intellisense-Popups...
Both, WV.jsRun and WV.jsRunAsync expect a "function-name" in the first argument.
So, the easiest way is, to "wrap the little code-block" in your own user-function - as e.g.:
WV.AddScriptToExecuteOnDocumentCreated "function scrollSmoothlyBy(x,y){ window.scrollBy({left:x, top:y, behavior:'smooth'}) }"
You can then later call it e.g. this way (passing the x,y arguments after the function-name):
WV.jsRunAsync "scrollSmoothlyBy", 5, 15
As for extensions like AdBlock... those were not supported the last time I've looked...
Here's a posting on stack-overflow: https://stackoverflow.com/questions/...on-on-webview2
Olaf
-
Mar 5th, 2023, 04:42 PM
#270
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Can I get the current URL somehow?
-
Mar 5th, 2023, 04:54 PM
#271
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
Would you recommend to add all the functions that I need for example at program start up, correct?
-
Mar 5th, 2023, 05:14 PM
#272
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I am adding this code via "wv.AddSCriptToExecuteOnDocumentCreated" when initiating WV:
Code:
function pSetFocus()
{
alert('focus');
var element = document.querySelector("*[autofocus]");
if (element)
{
}
else
{
element = document.querySelector("form input:not([type=hidden])");
}
if (element)
{
}
else
{
element = document.querySelector("input#search");
}
if (element)
{
}
else
{
element = document.querySelector("input#search.ytd-searchbox");
}
if (element)
{
}
else
{
}
if (element)
{
var sType=element.type;
if (sType != "email")
{
element.selectionStart = element.selectionEnd = element.value.length;
}
element.focus();
var y = element.getBoundingClientRect().top + window.scrollY;
window.scroll(
{
top: y,
behavior: "smooth"
});
}
Then, when I want to set the focus to the first input element, I call:
Code:
WV.SetFocus FocusReason_PROGRAMMATIC
WV.jsRunAsync "pSetFocus();"
It doesn't have any effect.
What am I doing wrong?
-
Mar 5th, 2023, 08:27 PM
#273
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
Then, when I want to set the focus to the first input element, I call:
Code:
WV.SetFocus FocusReason_PROGRAMMATIC
WV.jsRunAsync "pSetFocus();"
It doesn't have any effect.
What am I doing wrong?
Olaf just said that it expects a function name so I'd expect that your code should be this instead:-
Code:
WV.jsRunAsync "pSetFocus"
-
Mar 5th, 2023, 08:46 PM
#274
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I have tried that as well, it doesn't work.
-
Mar 5th, 2023, 09:08 PM
#275
Re: VB6 WebView2-Binding (Edge-Chromium)
Ah well that's all I got. I have no experience using WebView. Perhaps someone else can try their hand at the problem.
-
Mar 5th, 2023, 09:10 PM
#276
Hyperactive Member
Re: VB6 WebView2-Binding (Edge-Chromium)
I was stupid. My JS code was faulty. I've been using a different browser before, and it was more foregiving.
Once I fixed it, it went fine!
Last edited by tmighty2; Mar 5th, 2023 at 09:37 PM.
-
Mar 6th, 2023, 12:48 AM
#277
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by tmighty2
Would you recommend to add all the functions that I need for example at program start up, correct?
Of course... and you don't have to call: WV.AddScriptToExecuteOnDocumentCreated
for every little function-snippet separately (after the Bind-call was successful).
Easier would be, when you place all your helper-functions in a single "MyHelpers.js"-file...
and then use an UTF8-capable TextFile-ReadHelper to load them in a single line of code:
WV.AddSCriptToExecuteOnDocumentCreated New_c.FSO.ReadTextContent("MyHelpers.js", False, CP_UTF8)
And when you use a decent TextEditor like VSCode to edit this js-File, then you'd also produce less "basic typos with js-syntax",
since this Editor will give you nice "visual hints" about "missing parentheses" or "missing quotechars around strings".
As for "how to get the current Document-Title or Document-URL" -
there's already two Properties in place on the cWebView2-class:
- WV.DocumentURL
- WV.DocumentTitle
Please do some "basic investigations" on the library (RC6) or current Class (RC.cWebView2) first,
before you start working on something concrete... (e.g.via ObjectExplorer, reachable via <F2>-Key).
There's only about 50 Methods, Properties and Events behind the WV2-class -
(and half of them are "IsThatEnabled" or "AreTheseAllowed" basic boolean-Props).
Olaf
-
Mar 6th, 2023, 04:59 AM
#278
Re: VB6 WebView2-Binding (Edge-Chromium)
GetEdgeWebViewInfo:
---------------------------
Microsoft Edge WebView2 Runtime,Version:110.0.1587.63
---------------------------
Code:
Function GetEdgeWebViewInfo(Optional CheckX64 As Boolean) As String
On Error Resume Next
Dim WshShell As Object
Dim WebView2_Version As String, WebView2_Name As String
Dim RegPath As String
Set WshShell = CreateObject("Wscript.Shell")
RegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\" & IIf(CheckX64, "WOW6432Node\", "") & "Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}\"
'InputBox "", "", RegPath
WebView2_Name = WshShell.RegRead(RegPath & "name")
WebView2_Version = WshShell.RegRead(RegPath & "PV")
GetEdgeWebViewInfo = WebView2_Name & IIf(WebView2_Version <> "", ",Version:" & WebView2_Version, "")
End Function
Last edited by xiaoyao; Mar 6th, 2023 at 05:03 AM.
-
Mar 6th, 2023, 05:50 PM
#279
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Schmidt
Not sure, whether the following example does what you had in mind -
but the demo below will suppress the "WV2-built-in default-BrowserWindow-Popups",
and will simply create additional VB-Form-instances instead (each using their own internal WV-Instance of course).
Code:
Option Explicit
Public WithEvents WV As cWebView2, WithEvents tmrNewWindow As cTimer
Public Sub ShowNewWindow(NewWindowFeatures As cCollection)
Set tmrNewWindow = Nothing 'we can safely destroy the "one-shot"-timerInstance now (since it delivered its Tag-Data)
*************
F.Caption = .Prop("URI")
F.WV.Navigate .Prop("URI")
Debug.Print .SerializeToJSONString '(just to show, what else is contained in the features-collection)
End With
End Sub
HTH
Olaf
if new webview by post, how to do?not only by url
F.WV.Navigate .Prop("URI")
maybe need like webbrowser
postdata="user=abcd&pass=aaabbb"
httpheadStr="ref=www.baidu.com" & vbcrlf & "header2key=333"
webbrowser1.Navigate url,httpheadStr,postdata
in java,new webview only need input webview ID,IT WILL AUTO DO POSTdada or http header info.
Code:
Function WebPost(url As String, PostInfo As String, Web1 As WebBrowser, Optional ref As String, Optional cookie As String)
'[mycode_id:1274],edittime:2011-5-10 上午 12:26:45
On Error Resume Next
ReDim AByte(0) As Byte
PackBytes AByte(), PostInfo
Dim vPost As Variant
vPost = AByte ' Assign the byte array to a VARIANT
Dim vHeaders As Variant
vHeaders = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
If ref <> "" Then vHeaders = vHeaders & "Referer:" + ref & vbCrLf
If cookie <> "" Then vHeaders = vHeaders & "Cookie:" + cookie & vbCrLf
Web1.Navigate url, , , vPost, vHeaders
End Function
-
Mar 6th, 2023, 06:19 PM
#280
Re: VB6 WebView2-Binding (Edge-Chromium)
Originally Posted by Schmidt
Win10 has direct support for unpacking of *.cab-Archives -
otherwise use 7zip?
In any case, you should end up with an unpacked Folder, named:
..\Microsoft.WebView2.FixedVersionRuntime.107.0.1418.62.x86
somewhere on your local harddisk.
Now move that whole Folder to a place you prefer in your filesystem -
and then point the 3rd Param of the BindTo-method to that Directory-Path-(String).
Olaf
Code:
OK = Web1.BindTo(Me.hWnd, , App.Path & "\WebviewSdk\Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.x86") <> 0
'OK = Web1.BindTo(Me.hWnd, , App.Path & "\WebviewSdk\Microsoft.WebView2.FixedVersionRuntime.110.0.1587.63.x86") <> 0
msgbox "web1.UserAgent=" & WV.UserAgent
msgbox "navigator.appVersion=" & Web1.jsProp("navigator.appVersion")
view webview version online:
https://ie.icoa.cn/
====================
Microsoft.WebView2.FixedVersionRuntime.109.0.1518.78.x86.cab
内核版本 (Version) WebKit 537.36 Chrome 109.0.0.0
完整代码 (UA)
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78
====================
Microsoft.WebView2.FixedVersionRuntime.110.0.1587.63.x86.cab:
内核版本 (Version) WebKit 537.36 Chrome 110.0.0.0
完整代码 (UA)
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63
Last edited by xiaoyao; Mar 6th, 2023 at 07:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|