Results 1 to 12 of 12

Thread: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

  1. #1

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,195

    [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    This is a drop-in replacement of vbRichClient6's cWebView2 class, implemented in pure VB6 directly against the official Microsoft WebView2 COM API.

    No RC6.dll dependency, no dependency on the WebView2 SDK typelib — the only redistributable is WebView2Loader.dll authored by Microsoft deployed next to your exe, targeting the Evergreen WebView2 Runtime installed on the client machine.

    Additions beyond RC6 parity

    Methods with no RC6 counterpart, exposed because the native plumbing is cheap and the features are frequently requested:

    • PrintToPdf(ResultFilePath, [SecondsToWaitForPrintComplete], [Landscape], [ScaleFactor], [PageWidth/PageHeight], [margins], [ShouldPrintBackgrounds], [ShouldPrintSelectionOnly], [ShouldPrintHeaderAndFooter], [HeaderTitle], [FooterUri]) - blocking (or fire-and-forget at 0 seconds), returns True/False, Empty on timeout.
    • AddBrowserExtension(ExtensionFolderPath) - installs an unpacked extension into the profile, returns the extension Id (empty string on failure). Requires BindTo's AreBrowserExtensionsEnabled:=True optional parameter - must be decided before environment creation, and all instances sharing a user data folder must agree on it.
    • GetBrowserExtensions() - returns a Collection of per-extension Collections (Id, Name, IsEnabled keys), keyed by extension Id. Extension APIs need a recent Evergreen runtime; on older runtimes these return empty results.
    • SetVirtualHostNameToFolderMapping(HostName, FolderPath, [AccessKind]) / ClearVirtualHostNameToFolderMapping(HostName) - serve a local folder as https://<HostName>/... AccessKind defaults to HostResourceAccess_DENY (the mapped origin still serves its own content; other origins can't read it - Microsoft's recommended default). Mappings persist for the browser instance's lifetime: set once after BindTo, then navigate. The host name must be a bare name - no scheme or slashes.
    • Stop_ - cancels in-flight navigation/loading, WebBrowser.Stop style (trailing underscore because Stop is a VB6 keyword).
    • PostWebMessageAsString/PostWebMessageAsJson - host-to-page messaging; page script receives via chrome.webview.addEventListener('message', ...).
    • ContainsFullScreenElement - detect HTML fullscreen (resize/borderless the host form).
    • IsBuiltInErrorPageEnabled - the one base setting RC6 didn't surface.
    • IsMuted (get/let), IsDocumentPlayingAudio - tab audio control.
    • Default download dialog control - OpenDefaultDownloadDialog/CloseDefaultDownloadDialog/IsDefaultDownloadDialogOpen, DefaultDownloadDialogCornerAlignment and DefaultDownloadDialogMargin.
    • Profile properties - PreferredColorScheme (dark mode), DefaultDownloadFolderPath, PreferredTrackingPreventionLevel, ProfileName, ProfilePath, IsInPrivateModeEnabled.
    • StatusBarText, BrowserVersion - runtime/status introspection; OpenTaskManagerWindow - browser diagnostics.
    • CallDevToolsProtocolMethodForSession - CDP against a specific target session, same blocking semantics as CallDevToolsProtocolMethod.
    • SetBoundsAndZoomFactor, NotifyParentWindowPositionChanged (also called internally on resize/move), HosthWnd is now writable (re-hosting).
    • TrySuspend/ResumeFromSuspend/IsSuspended - release memory while in the background; TrySuspend hides the webview first (a native precondition), ResumeFromSuspend makes it visible again.
    • ClearBrowsingData(DataKinds), ClearBrowsingDataInTimeRange(DataKinds, StartTime, EndTime), ClearBrowsingDataAll - clear cache/cookies/history etc per eWebView2BrowsingDataKinds flags; blocking with the usual fire-and-forget at 0 seconds.
    • Cookie management - GetCookies([URI]) returns a Collection of per-cookie Collections (Name, Value, Domain, Path, IsSession, Expires, IsSecure, IsHttpOnly, SameSite keys); AddOrUpdateCookie(Name, Value, Domain, [Path], [Expires], ...) (zero Expires = session cookie); DeleteCookies(Name, URI) (both required - cookies are matched by name and URI natively); DeleteAllCookies.
    • PrintToPdfStream([settings...]) - same settings as PrintToPdf but returns the PDF as a Byte() array, no file involved. ShowPrintUI opens the browser or system print dialog.


    A handful of native WebView2/WebBrowser-style events with no RC6 counterpart are also exposed, since the native plumbing is either free (already needed for something else) or fills a gap the JS-bridge-based events can't:

    • ContentLoading(IsErrorPage) - fires before NavigationCompleted, akin to WebBrowser's early loading moment.
    • HistoryChanged() - back/forward stack changed; pair with CanGoBack/CanGoForward.
    • WindowCloseRequested() - page called window.close().
    • ZoomFactorChanged() - native counterpart to the ZoomFactor property.
    • MoveFocusRequested(Reason, Handled) - Tab/Shift+Tab reached the edge of the web content; Reason reuses eWebView2FocusReason.
    • DOMContentLoaded() - the classic DOM-ready moment, between ContentLoading and DocumentComplete.
    • StatusBarTextChanged(Text) - hover-link/status text, pairs with the StatusBarText property.
    • ContainsFullScreenElementChanged() - page entered/left HTML fullscreen; read ContainsFullScreenElement to react.
    • BasicAuthenticationRequested(URI, Challenge, UserName, Password, Cancel) - supply credentials for HTTP basic/proxy auth via the ByRef params. Note Chromium's flow: the challenged navigation first completes with WebErrorStatus 17 (VALID_AUTHENTICATION_CREDENTIALS_REQUIRED), then the authenticated retry loads.
    • ContextMenuRequested(PageURI, LinkURI, SelectionText, ScreenX, ScreenY, Handled) - the native context-menu event, richer than the JS-injected UserContextMenu (which only reports coordinates): carries link/selection info and can actually suppress the browser's context menu via Handled. Deliberately simplified - no custom menu item injection/CustomItemSelected. UserContextMenu is unchanged and still fires alongside it.

    cheers,
    </wqw>

  2. #2
    Addicted Member
    Join Date
    Oct 2014
    Posts
    132

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Quote Originally Posted by wqweto View Post
    This is a drop-in replacement of vbRichClient6's cWebView2 class, implemented in pure VB6 directly against the official Microsoft WebView2 COM API.

    No RC6.dll dependency, no dependency on the WebView2 SDK typelib — the only redistributable is WebView2Loader.dll authored by Microsoft deployed next to your exe, targeting the Evergreen WebView2 Runtime installed on the client machine.

    cheers,
    </wqw>
    wqweto, hello! Great job! The cWebView2 features you provided are really powerful and have been a huge help to me. Thank you so much!

  3. #3
    Addicted Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    139

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Fantastic job! I'm going to test this right away!

  4. #4

  5. #5
    Addicted Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    139

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    I dreamed of it, and you made it happen! Thank you!!

    Do you think it would be possible to add some features currently available in the latest versions of WebView2?

    For example:


    Thanks for your reply!
    François

  6. #6

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,195

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Claude just released version 1.0.1

    What's new

    • PrintToPdf method — saves the current page to PDF with optional orientation, scale, page size, margins and header/footer settings
    • Browser extension management — AddBrowserExtension/GetBrowserExtensions methods and new AreBrowserExtensionsEnabled optional parameter of BindTo
    • SecondsToWaitForXxx=0 and jsCallTimeOutSeconds=0 now mean fire-and-forget (execute async, return success immediately)
    • Deterministic teardown on Shutdown (controller Close), re-binding after Shutdown supported, missing loader reported immediately instead of as timeout

    cheers,
    </wqw>

  7. #7
    Addicted Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    139

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Quote Originally Posted by wqweto View Post
    Claude just released version 1.0.1

    What's new

    • PrintToPdf method — saves the current page to PDF with optional orientation, scale, page size, margins and header/footer settings
    • Browser extension management — AddBrowserExtension/GetBrowserExtensions methods and new AreBrowserExtensionsEnabled optional parameter of BindTo
    • SecondsToWaitForXxx=0 and jsCallTimeOutSeconds=0 now mean fire-and-forget (execute async, return success immediately)
    • Deterministic teardown on Shutdown (controller Close), re-binding after Shutdown supported, missing loader reported immediately instead of as timeout

    cheers,
    </wqw>
    Wow... I'm speechless, stunned, dumbfounded!
    It couldn't be faster!
    You're the best! Thank you!

  8. #8
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    634

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    very good work.
    I'm having trouble adding extensions.

    SOLVED
    Thanks
    Last edited by yokesee; Yesterday at 12:52 PM.

  9. #9
    Addicted Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    139

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Um... ..., I hardly dare ask...

    Can Claude.wqweto.ai do anything about SetVirtualHostNameToFolderMapping ? ? ?

    ...I'm going to hide and pray in my cave...

    François

  10. #10

  11. #11

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,195

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Download: VbWebView2 1.0.3

    What's new

    • Cookie management — GetCookies, AddOrUpdateCookie, DeleteCookies, DeleteAllCookies
    • BasicAuthenticationRequested event — supply credentials for HTTP basic/proxy auth
    • PrintToPdfStream method — current page as PDF in a Byte() array, no file involved; ShowPrintUI opens the print dialog
    • TrySuspend/ResumeFromSuspend/IsSuspended — release memory while in the background
    • ClearBrowsingData/ClearBrowsingDataInTimeRange/ClearBrowsingDataAll — clear cache/cookies/history per eWebView2BrowsingDataKinds flags
    • New events — DOMContentLoaded, StatusBarTextChanged, ContainsFullScreenElementChanged
    • Profile properties — PreferredColorScheme (dark mode), DefaultDownloadFolderPath, PreferredTrackingPreventionLevel, ProfileName, ProfilePath, IsInPrivateModeEnabled
    • Host-to-page messaging — PostWebMessageAsString/PostWebMessageAsJson
    • Assorted — Stop_, IsMuted/IsDocumentPlayingAudio, default download dialog control, ContainsFullScreenElement, IsBuiltInErrorPageEnabled, StatusBarText, BrowserVersion, OpenTaskManagerWindow, CallDevToolsProtocolMethodForSession, SetBoundsAndZoomFactor, NotifyParentWindowPositionChanged, writable HosthWnd
    • GetMostRecentInstallPath now fills VersionString with the resolved runtime version instead of raising "not yet implemented"

    cheers,
    </wqw>

  12. #12
    Addicted Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    139

    Re: [VB6] cWebView2 — RC6-compatible WebView2 wrapper

    Quote Originally Posted by wqweto View Post
    Download: VbWebView2 1.0.3

    What's new

    • Cookie management — GetCookies, AddOrUpdateCookie, DeleteCookies, DeleteAllCookies
    • BasicAuthenticationRequested event — supply credentials for HTTP basic/proxy auth
    • PrintToPdfStream method — current page as PDF in a Byte() array, no file involved; ShowPrintUI opens the print dialog
    • TrySuspend/ResumeFromSuspend/IsSuspended — release memory while in the background
    • ClearBrowsingData/ClearBrowsingDataInTimeRange/ClearBrowsingDataAll — clear cache/cookies/history per eWebView2BrowsingDataKinds flags
    • New events — DOMContentLoaded, StatusBarTextChanged, ContainsFullScreenElementChanged
    • Profile properties — PreferredColorScheme (dark mode), DefaultDownloadFolderPath, PreferredTrackingPreventionLevel, ProfileName, ProfilePath, IsInPrivateModeEnabled
    • Host-to-page messaging — PostWebMessageAsString/PostWebMessageAsJson
    • Assorted — Stop_, IsMuted/IsDocumentPlayingAudio, default download dialog control, ContainsFullScreenElement, IsBuiltInErrorPageEnabled, StatusBarText, BrowserVersion, OpenTaskManagerWindow, CallDevToolsProtocolMethodForSession, SetBoundsAndZoomFactor, NotifyParentWindowPositionChanged, writable HosthWnd
    • GetMostRecentInstallPath now fills VersionString with the resolved runtime version instead of raising "not yet implemented"

    cheers,
    </wqw>
    incredible ! It's a dream !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width