AccessWebview is a self-contained, 32-bit (x86) and 64-bit (x64) Microsoft Access VBA WebView2 framework adapted from tarboh/WebView2-For-Excel-VBA (v0.5.2). It drives the native WebView2Loader.dll shipped inside Microsoft Office\root\Office16\ alongside MSACCESS.EXE using oleaut32!DispCallFunc, SAFEARRAY pointer primitives, and dual-architecture (x86 / x64) VBE7.DLL-guarded machine-code callback thunks.
It requires zero COM/ActiveX registration, zero VBA Tools -> References beyond standard Access defaults, zero admin privileges, and zero MSysResources Trusted Domains configuration—unlocking direct chrome.webview.hostObjects DAO RPC, event-driven postMessage, SetVirtualHostNameToFolderMapping local SPA hosting, F12 DevTools, Playwright-style DOM automation, and HTTP request/response capture inside Microsoft Access forms.
- Directory Layout & Module Inventory
- Installation & Integration Guide
- Quick-Start Recipes
- Architecture Overview
- Low-Level COM & Callback Thunk Internals (
Wv2Thunks&ComCallbackHandler) - Access Windowing & Form Lifecycle (
clsWv2Host,modWv2AccessHost&frmWv2Surface) - Core Browser & Viewport API Reference (
Wv2Environment&Wv2Pane) - JavaScript <-> Access VBA / DAO IPC Patterns
- DOM Automation & SPA Quiescence API (
Wv2Element&Wv2PaneD-Axis) - Network Traffic Inspection & Capture API (
Wv2PaneN-Axis) - Multi-Tab Management & Deferred Timers (
Wv2Browser,SafeTimer,LibTimers) - 32-Bit (
x86) vs. 64-Bit (x64) ABI & Edge-Case Guarantees - Comparison:
AccessWebviewvs. Native AccessEdgeBrowserControl - Diagnostics, Logging (
Wv2Log), Testing & Troubleshooting
| File / Folder | Purpose |
|---|---|
./AccessWebview.accdb |
Reference host database (compiled & verified in 32-bit MSACCESS.EXE 16.0.20430.20180; compatible with 64-bit Access) |
./spa/index.html |
Sample dark-mode SPA mounted at https://appassets.access.local/index.html demonstrating hostObjects.vba DAO CRUD + bidirectional postMessage |
./src/ |
Exported 7-bit ASCII VBA source for all 17 modules, classes, and Access forms (managed via XLIDE) |
./AccessWebview-Live-Verified.png |
Live screenshot of frmWv2Demo running in 32-bit Microsoft Access |
./README.md / ./README.html |
Developer documentation (Markdown & standalone HTML) |
Depending on whether you are building a single-pane Access SPA or a multi-tab automation browser, you can import either the Lean SPA Core (10 objects, plus SafeTimer & LibTimers) or the Full Suite (17 objects):
| Module / Form | Type | Tier | Lines | Responsibility |
|---|---|---|---|---|
Wv2Thunks.bas |
Standard | Core | 2,716 | WebView2Loader.dll declaration, DispCallFunc (dcf), VirtualAlloc 512-slot callback pool, x86/x64 machine-code thunks, IID table, SAFEARRAY memory primitives, and VBE Reset Sentinel |
ComCallbackHandler.cls |
Class | Core | 166 | Receives all 13 HandlerKind COM callbacks at fixed vtable slot 7 (Handler_Invoke) and routes them to owner classes |
Wv2Environment.cls |
Class | Core | 255 | Asynchronous ICoreWebView2Environment bootstrapper and COM pointer lifetime wrapper |
Wv2Pane.cls |
Class | Core | 8,006 | ICoreWebView2Controller + ICoreWebView2 / _2 / _3 wrapper, EvalSync, DOM queries, quiescence probes, and network capture |
Wv2Element.cls |
Class | Core | 489 | Generation-checked DOM element handle (InnerText, InnerHTML, Value, Click, GetAttribute, SetAttribute) |
Wv2Json.bas |
Standard | Core | 373 | Pure-VBA JSON escaping, unescaping (including UTF-16 surrogate pairs), and lightweight key extraction |
Wv2Log.bas |
Standard | Core | 514 | Sequenced UTF-8 file logger (%APPDATA%\Wv2Browser\logs) with automatic log rotation |
clsWv2Host.cls |
Class | Core | 167 | Persistent Access WebView2 controller host that survives Access Subform (OFormChild) recreation during grow/maximize resizes |
modWv2AccessHost.bas |
Standard | Core | 440 | Access OFormSub / OFormChild HWND resolver, clsWv2Host registry, Z-order sync, and 4-step self-test suite |
Form_frmWv2Surface.cls |
Form | Core | 129 | Reusable borderless Access Subform canvas (InitSpa, ResizeViewport, ShutdownWebView) backed by clsWv2Host |
clsWv2AccessBridge.cls |
Class | App | 152 | Example DAO RPC bridge exposed to JavaScript as window.chrome.webview.hostObjects.vba |
Form_frmWv2Demo.cls |
Form | App | 106 | Example Access host form combining native Access header controls with frmWv2Surface |
Wv2Browser.cls |
Class | Multi-Tab | 2,860 | Multi-tab controller, tab events, and put_NewWindow prewarmed popup tab delegation |
SafeTimer.cls |
Class | Multi-Tab | 90 | Break-safe Win32 timer backed by a message-only window (HWND_MESSAGE = -3) for deferred async actions outside WebView2 callbacks |
LibTimers.bas |
Standard | Multi-Tab | 127 | x86 + x64 VBE7 EntryPoint timer callback thunk for SafeTimer |
Wv2Url.bas |
Standard | Multi-Tab | 155 | UTF-8 percent-encoding (UrlEncodeComponent) and URL scheme helpers |
Wv2SettingsBridge.cls |
Class | Multi-Tab | 654 | Search-engine preset persistence helper used by Wv2Browser |
- Microsoft Access 2016 / 2019 / 2021 / LTSC / Microsoft 365 (
32-bit x86or64-bit x64). WebView2Loader.dll: Automatically resolved fromMicrosoft Office\root\Office16\WebView2Loader.dll(installed right besideMSACCESS.EXE, so Windows loads the exact matchingx86orx64binary first under standard DLL search order).- Microsoft Edge WebView2 Evergreen Runtime: Pre-installed on Windows 10 (21H2+) and Windows 11 (
C:\Program Files (x86)\Microsoft\EdgeWebView\Application).
Zero External References: Only the standard built-in Access VBA references (
VBA,Access,stdole, andDAOif your bridge queries tables) are needed. Do not add references toMicrosoft Internet Controls,Microsoft HTML Object Library, or any.tlb/.dll.
- Import the Core Modules:
Copy or importWv2Thunks,ComCallbackHandler,Wv2Environment,Wv2Pane,Wv2Element,Wv2Json,Wv2Log,SafeTimer,LibTimers,clsWv2Host,modWv2AccessHost, and the reusable formfrmWv2SurfacefromAccessWebview.accdbinto your front-end.accdb(External Data -> New Data Source -> From Database -> Access). - Drop
frmWv2Surfaceonto Your Host Form:- Open your host form in Design View and add a Subform/Subreport control named
subWebViewwithSourceObject = "frmWv2Surface",BorderStyle = Transparent (0). - If using Access layout anchoring, set
HorizontalAnchor = BothandVerticalAnchor = Both—or resizeMe.subWebViewexplicitly inForm_Resize(recommended for pixel-tight full-bleed layouts).
- Open your host form in Design View and add a Subform/Subreport control named
- Create Your Bridge Class:
Create a standard VBA class module (e.g.,clsAppBridge) withPublic Function/Public Submethods. Every VBA class automatically implementsIDispatch, so WebView2 exposes itsPublicmembers directly to JavaScript when passed toInitSpaorView_AddHostObjectToScript. - Compile Before First Run:
In the VBA Editor (Alt+F11), click Debug -> Compile<ProjectName>and save. Compiling ensures all standard-moduleAddressOffunction pointers (Handler_QueryInterface,Handler_AddRef,Handler_Release,EntryPoint) are materialized before Win32 APIs invoke them.
Place your index.html, .js, and .css assets in a local folder (e.g., CurrentProject.Path & "\spa"). Inside your Access host form:
Option Compare Database
Option Explicit
Private m_bridge As clsWv2AccessBridge
Private Sub Form_Load()
Set m_bridge = New clsWv2AccessBridge
Dim surf As Form_frmWv2Surface
Set surf = Me.subWebView.Form
' Mounts folder at https://appassets.access.local/index.html and attaches m_bridge as hostObjects.vba
If Not surf.InitSpa( _
virtualHostName:="appassets.access.local", _
localFolderPath:=CurrentProject.Path & "\spa", _
entryFile:="index.html", _
hostObject:=m_bridge, _
hostObjectName:="vba") Then
MsgBox "WebView2 failed to initialize.", vbExclamation
End If
End Sub
Private Sub Form_Resize()
On Error Resume Next
Me.subWebView.Move 0, 0, Me.InsideWidth, Me.InsideHeight - Me.FormHeader.Height
Me.subWebView.Form.ResizeViewport
On Error GoTo 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Me.subWebView.Form.ShutdownWebView
Set m_bridge = Nothing
On Error GoTo 0
End SubInside your JavaScript (spa/index.html):
// Asynchronous call (non-blocking Promise — preferred for UI responsiveness)
const tasksJson = await window.chrome.webview.hostObjects.vba.GetTasksJson();
const tasks = JSON.parse(tasksJson);
// Synchronous call (blocks JS until VBA returns)
const hostJson = window.chrome.webview.hostObjects.sync.vba.GetHostInfoJson();When you want to render charts, Markdown previews, or interactive cards from HTML generated purely in VBA without writing files to disk:
Public Sub LoadInlineHtmlCard(ByVal surf As Form_frmWv2Surface)
Dim env As New Wv2Environment
env.Init GetDefaultUserDataFolder()
Do While Not env.IsReady And Not env.IsFailed: DoEvents: Loop
Dim pane As New Wv2Pane
pane.Init env, GetAccessFormCanvasHwnd(surf)
Do While Not pane.IsReady And Not pane.IsFailed: DoEvents: Loop
pane.Ctrl_GetCoreWebView2
pane.View_AddNavigationCompleted
pane.View_AddWebMessageReceived
Dim rc As RECT
GetClientRect GetAccessFormCanvasHwnd(surf), rc
pane.Ctrl_PutBounds rc
pane.Ctrl_PutIsVisible True
pane.View_NavigateToString _
"<!doctype html><html><body style='font-family:Segoe UI;padding:20px'>" & _
"<h2>Inline Access Report</h2>" & _
"<button onclick=""chrome.webview.postMessage('export-clicked')"">Export</button>" & _
"</body></html>"
End SubNote:
View_NavigateToStringhas anabout:blankorigin and a ~2 MB string limit. Whenever your app uses ES modules (<script type="module">),fetch()to local assets,localStorage, orhistory.pushStaterouting, useInitSpa/View3_SetVirtualHostNameToFolderMappinginstead so your app runs under a genuine securehttps://origin.
Public Sub AutomatePortalSearch(ByVal p As Wv2Pane, ByVal queryText As String)
p.View_Navigate "https://example.org"
' 1. Wait up to 10s for an input element to appear in the DOM
Dim searchBox As Wv2Element
Set searchBox = p.WaitFor("#search-input", 10)
If searchBox Is Nothing Then Exit Sub
' 2. Arm a network or URL signal BEFORE triggering the UI action
p.ArmNetworkSignal "/api/search"
' 3. Assign .value (uses native HTMLInputElement prototype setter so React/Vue state updates!)
searchBox.value = queryText
p.QuerySelector("#submit-btn").Click
' 4. Wait until in-flight fetch/XHR + DOM mutations settle
If p.WaitSettled(timeoutSec:=15, quietMs:=400) Then
Dim rows As Collection
Set rows = p.QuerySelectorAll(".result-item")
Dim item As Wv2Element
For Each item In rows
Debug.Print item.InnerText
Next item
End If
End SubAccessWebview is structured in five strict layers so low-level pointer/thunk mechanics never leak into form or business logic:
+----------------------------------------------------------------------------------------+
| Layer 5: Access Application & UI Layer |
| frmWv2Demo (Host Form) | clsWv2AccessBridge (DAO / Business Logic via IDispatch) |
+----------------------------------------------------------------------------------------+
| Layer 4: Reusable Access Host Surface |
| frmWv2Surface (Borderless Subform) | modWv2AccessHost (OFormSub HWND & Test Suite) |
+----------------------------------------------------------------------------------------+
| Layer 3: High-Level Browser, DOM & Network Abstractions |
| Wv2Element (DOM Handle) | Wv2Browser (Multi-Tab + Prewarm) | Wv2Json / Wv2Log |
+----------------------------------------------------------------------------------------+
| Layer 2: Core WebView2 COM Wrappers |
| Wv2Environment (ICoreWebView2Environment) |
| Wv2Pane (ICoreWebView2Controller + ICoreWebView2 / _2 / _3 + IStream + Headers) |
+----------------------------------------------------------------------------------------+
| Layer 1: Zero-Reference COM Dispatch & Dual-Bitness Callback Thunk Pool |
| Wv2Thunks.bas (DispCallFunc, SAFEARRAY PointerAccessor, VirtualAlloc 512-Slot Pool, |
| VBE7 EbMode Stub + x86/x64 Machine-Code Thunks, Reset Sentinel) |
| ComCallbackHandler.cls (Fixed Slot-7 Handler_Invoke Router for 13 HandlerKinds) |
+----------------------------------------------------------------------------------------+
| Native OS / Office Binaries (Pre-Installed — Zero Registration) |
| Office16\WebView2Loader.dll --> EdgeWebView\...\EmbeddedBrowserWebView.dll |
+----------------------------------------------------------------------------------------+
WebView2 exposes pure C++ IUnknown-derived vtable interfaces (ICoreWebView2, ICoreWebView2Controller, etc.) rather than late-bound IDispatch interfaces, and its type library is not registered in the Windows Registry. Wv2Thunks.dcf invokes any COM method directly by 0-based vtable index (0 = QueryInterface, 1 = AddRef, 2 = Release, 3+ = interface methods):
Public Function dcf( _
ByVal pInterface As LongPtr, _
ByVal vtblIndex As Long, _
ByVal funcName As String, _
ParamArray args() As Variant) As LongArgument Marshaling Rules in dcf:
vbLong-> passed as 4-byte integer (VT_I4).vbDouble-> passed as 8-byte IEEE float (VT_R8).vbCurrency-> passed as 8-byte raw 64-bit integer value (VT_CY) on bothx86andx64(used forEventRegistrationTokeninremove_*calls andLARGE_INTEGERoffsets inIStream::Seek).vbLongLong(onWin64) -> passed as 8-byteLongPtr(VT_I8).Elsefallback ->vbLongLongonWin64,vbLongon32-bit x86.- Out-Pointers (
[out] void**,[out] LPWSTR*): PassVarPtr(localVar). Strings returned by WebView2 (LPWSTR*) are copied into a VBABSTRviaPtrToStringand freed immediately viaole32!CoTaskMemFree(GetStringPropertyhandles all three steps automatically). - Return Value Contract:
dcfdoes not assume non-zero means failure, becauseIUnknown::AddRefandReleasereturnULONGreference counts (1, 2, ...) rather thanHRESULTs. Callers checkhr <> 0onHRESULT-returning methods.
Every asynchronous WebView2 operation (CreateCoreWebView2EnvironmentWithOptions, CreateCoreWebView2Controller, ExecuteScript, GetContent, and all 9 browser events) requires the host to supply a custom COM callback object whose vtable is:
Slot 0:QueryInterface(this, riid, ppvObject)Slot 1:AddRef(this)Slot 2:Release(this)Slot 3:Invoke(this, arg1, arg2)
Because a VBA class module's vtable places IDispatch in slots 3..6, puts its first user method at slot 7, expects ObjPtr(instance) as hidden arg0, and returns Function results through a hidden trailing HRESULT* out-parameter, Wv2Thunks.Thunks_Init allocates a single 114,752-byte PAGE_EXECUTE_READWRITE region containing a 64-byte header (byte 0 = pool alive flag) plus 512 reusable 224-byte callback slots:
Slot Layout (224 bytes per slot; pVTableObj = pSlot + 176 passed to WebView2 as `this`):
+0..+90 : Cloned VBE7 EntryPoint stub (checks VBE7!EbMode; skips call in VBE Break mode!)
* x64: 91 bytes, jump target patched at +55 (LATE_BIND_OFFSET = 55)
* x86: 33 bytes, jump target patched at +22 (LATE_BIND_OFFSET = 22),
Break-mode epilogue at +28 patched from `C2 00 00` -> `C2 0C 00`!
+96..+169 : Per-slot Machine-Code Thunk
* Checks [pRegionBase] == 1 (returns S_OK = 0 immediately if Shutdown/Reset occurred)
* Shifts (this, arg1, arg2), injects ObjPtr(ComCallbackHandler), allocates retval,
and calls ComCallbackHandler.Handler_Invoke (vtable slot 7)
+176..+215 : Embedded COM Object + VTable (`VTABLE_OBJ_OFFSET = 176`)
* +176 : pVTable -> points to +184
* +184 + 0*Ptr : AddressOf Handler_QueryInterface (checks IID_IUnknown + m_iidTable(kind))
* +184 + 1*Ptr : AddressOf Handler_AddRef (increments ComCallbackHandler.RefCount)
* +184 + 2*Ptr : AddressOf Handler_Release (at RefCount=0, breaks owner cycle & frees slot)
* +184 + 3*Ptr : pSlot (Invoke -> VBE7 stub -> Machine-Code Thunk)
Invariant on
ComCallbackHandler.cls:Public Function Handler_Invoke(...)must remain the very first procedure/property inComCallbackHandler.cls(above allFriendproperties/subs) so its vtable index is guaranteed to be slot 7 on both 32-bit and 64-bit VBA.
PointerAccessor(MemLongPtr/ReadLongPtr): Instead of callingkernel32!RtlMoveMemoryon every pointer read/write (which triggers P/Invoke overhead andErr.LastDllErrorside effects),Wv2Thunksoverlays a 1-elementSAFEARRAY_1D(FADF_AUTO Or FADF_FIXEDSIZE) onto a typedLongPtr()array for native memory speed.- VBE Reset Sentinel (
WV2_VBA_LastRegion): Pressing the VBE Reset (Stop) button wipes all VBA module variables (m_pRegionBase = 0) without firingForm_Unload, leaving theVirtualAllocregion orphaned inMSACCESS.EXE.Thunks_Initstoresm_pRegionBasein process environment variableWV2_VBA_LastRegion. On the next initialization after a VBE Reset,Sentinel_RecoverIfNeededinspects the address viaVirtualQuery(MEM_COMMIT+ matchingAllocationBase+ read/write protection), zeroes the alive byte at+0so any stray WebView2 callback safely returnsS_OK, and frees the previous block withVirtualFree(..., MEM_RELEASE).
In Excel, MSForms UserForms host WebView2 inside a Frame control (Frame1.[_GethWnd]). In Microsoft Access, native controls (Rectangle, TextBox, CommandButton, TabControl) are windowless and have no HWND. Only Forms (OForm / OFormPopup) and Subforms (OFormChild) own real Win32 windows:
OFormPopup / OForm (Parent Form.hwnd — IMMORTAL across all resizes)
├── 1st OFormSub : FormHeader <-- Height is 0 px when the form has no header!
├── 2nd OFormSub : Detail <-- IMMORTAL section canvas (never recreated on resize!)
│ └── OFormChild (Subform.Form.hwnd) <-- EPHEMERAL! Destroyed & reloaded whenever Subform grows!
└── 3rd OFormSub : FormFooter <-- Height is 0 px when the form has no footer!
Hosting WebView2 reliably in Access requires solving two distinct Access windowing behaviors:
- Trap #1 — The
0 pxFormHeaderOFormSub:
Access always creates threeOFormSubchildren under everyForm.hwnd(FormHeader,Detail,FormFooter). CallingFindWindowExW(frm.hwnd, 0, StrPtr("OFormSub"), 0)on a headerless form returns the 1stOFormSub(FormHeader, height =0 px), clippingChrome_WidgetWin_0to0 pxheight! - Trap #2 — Subform
OFormChildDestruction & VBA Reload When Growing/Maximizing:
Whenever an AccessSubformcontrol (OFormChild) grows larger than its previous high-water size (dragging a window edge outward or clicking Maximize), Microsoft Access destroys theOFormChildWin32 window, firesSubform.Form_Unload, creates a brand-newOFormChildHWND, and instantiates a fresh VBAForm_frmWv2Surfaceinstance!- If
ICoreWebView2Controllerwere parented insideOFormChild, Win32DestroyWindowwould recursively destroyChrome_WidgetWin_0, turning the WebView blank permanently! - If
m_panelived directly onForm_frmWv2Surface,Form_Unloadwould closem_paneand the newly createdForm_frmWv2Surfacewould wake up withm_pane Is Nothing!
- If
AccessWebview solves both traps transparently via clsWv2Host + modWv2AccessHost:
- When
frmWv2Surfaceis hosted inside a Subform (GetWinClassName(Me.hwnd) = "OFormChild"),GetAccessFormCanvasHwndreturnsGetParent(Me.hwnd)—the parent form's immortal sectionOFormSub, which is never destroyed during shrink, grow, maximize, or restore. clsWv2Hostownsm_envandm_paneoutside the ephemeral subform instance and registers itself inmodWv2AccessHostkeyed byhostHwnd. When Access reloadsForm_frmWv2Surfaceduring a grow resize,EnsureHost()seamlessly reconnects the new subform instance to the liveclsWv2Host, maps the subform's screen bounds intohostHwndclient pixels viaMapWindowPoints, callsCtrl_PutBounds+Ctrl_NotifyParentWindowPositionChanged, and keepsChrome_WidgetWin_0atHWND_TOP(SyncAccessWebViewZOrder).
- Keep
frmWv2Surface.WidthSmall in Design View (1440twips = 1 inch):
If an Access subform's Design-ViewWidthis wider thansubWebView.Width, Access forces the innerOFormChildwidth toMax(subWebView.Width, frmWv2Surface.Width). KeepingfrmWv2Surface.Width = 1440andDetail.Height = 1440letsfrmWv2Surfaceshrink or expand to any container size cleanly. - Expand
Detail.HeightBeforesubWebView.HeightWhen Resizing in VBA:
If resizingsubWebViewinForm_Resize, Access rejectssubWebView.Height = targetHiftargetH > Me.Detail.Height. ExpandMe.Detail.Heightfirst when growing, and shrinkMe.subWebView.Heightfirst when shrinking (as shown inForm_frmWv2Demo.RefreshHeaderAndViewport). - Never Convert Twips to Pixels Manually:
GetAccessFormViewportRectuses Win32GetWindowRect+MapWindowPoints/GetClientRectdirectly in physical pixels, avoiding Twips-to-Pixels rounding drift across 100%, 125%, 150%, and Per-Monitor DPI v2 displays.
- Explicit Teardown: In your parent form's
Form_Unload, callMe.subWebView.Form.ShutdownWebViewandShutdownAccessFormWebViews Me(which tears down anyclsWv2Hostattached to the form'sOFormSubsections even if Access unloaded the subform first during a Form View -> Design View switch). - Automatic Orphan Safety Net: Whenever
frmWv2Surface.Form_Unloadfires on a subform,clsWv2Host.ScheduleOrphanCheckarms an 80 ms one-shotSafeTimer. IfForm_Unloadwas merely a resize-triggeredOFormChildswap,IsWindow(m_hostHwnd)is still non-zero and the WebView continues uninterrupted; if the parent form actually closed (even without parentForm_Unloadcode),IsWindow(m_hostHwnd)is0andclsWv2Host.Shutdownreleases all WebView2 COM pointers (View3 -> View2 -> View -> Controller -> Environment) automatically.
| Member | Signature | Description |
|---|---|---|
Init |
Sub Init(ByVal userDataPath As String) |
Calls CreateCoreWebView2EnvironmentWithOptions asynchronously. Creates userDataPath recursively if missing (defaults to C:\Temp\VBA_WebView2; modWv2AccessHost.GetDefaultUserDataFolder() returns %LOCALAPPDATA%\AccessWebview\UserData). |
IsReady / IsFailed |
Property Get () As Boolean |
Poll with DoEvents until IsReady or IsFailed becomes True. |
LastError |
Property Get () As Long |
HRESULT if initialization failed (0 = S_OK). |
EnvironmentPtr |
Property Get () As LongPtr |
Raw ICoreWebView2Environment* COM interface pointer. |
| Category | Method / Property | Description |
|---|---|---|
| Controller | Init(env, hwnd) |
Asynchronously creates ICoreWebView2Controller parented to hwnd. |
IsReady / IsFailed / LastError |
Readiness state of controller creation. | |
Ctrl_GetCoreWebView2() As Long |
Populates internal m_pView (ICoreWebView2*); call once immediately after IsReady = True. |
|
Ctrl_PutBounds(bounds As RECT) As Long |
Resizes browser viewport in parent client pixels (x86 4-Long stack ABI & x64 pointer ABI handled automatically). |
|
Ctrl_PutIsVisible(visible As Boolean) As Long |
Shows or hides the controller viewport (True normalized to Win32 BOOL = 1). |
|
Ctrl_Close() As Long |
Closes controller, zeroes persistent tokens, and prevents further script calls. | |
| Navigation | View_Navigate(url As String) As Long |
Navigates to an https://, http://, file:///, or virtual-host URL. |
View_NavigateToString(htmlContent As String) As Long |
Renders an in-memory HTML string directly (about:blank origin). |
|
View3_SetVirtualHostNameToFolderMapping(hostName, folderPath, accessKind) As Long |
Maps https://<hostName>/ to a local folder (0 = DENY, 1 = ALLOW, 2 = DENY_CORS). Always navigate to an explicit file (e.g., index.html), as root / returns ACCESS_DENIED. |
|
View_Reload() / View_Stop() |
Reloads current page or cancels in-progress navigation. | |
View_GoBack() / View_GoForward() |
Navigates session history (View_GetCanGoBack / View_GetCanGoForward check availability). |
|
View_GetSource() / View_GetDocumentTitle() |
Returns current URL or <title> string. |
|
| Settings & DevTools | Settings_PutAreDevToolsEnabled(v As Boolean) As Long |
Enables or disables F12 / programmatic DevTools. |
View_OpenDevToolsWindow() As Long |
Opens the Chromium DevTools inspector window (ICoreWebView2 vtable 51). |
|
Settings_PutAreDefaultContextMenusEnabled(v As Boolean) As Long |
Enables or suppresses the right-click browser context menu (set False for locked-down production Access apps). |
|
Settings_PutIsScriptEnabled(v As Boolean) As Long |
Enables or disables JavaScript execution on subsequent navigations. | |
| Events | View_AddNavigationStarting / View_AddNavigationCompleted |
Subscribes to navigation lifecycle (IsPageLoaded tracks completion). |
View_AddDocumentTitleChanged / View_AddHistoryChanged |
Tracks <title> updates and SPA pushState / replaceState / popstate URL transitions. |
|
View2_AddDOMContentLoaded |
Subscribes to ICoreWebView2_2::DOMContentLoaded (fires before external images/subresources finish). |
|
View_AddWebMessageReceived |
Enables Public Event WebMessageReceived(messageText, messageJson) and optional SetWebMsgSink forwarding. |
|
View_AddNewWindowRequested |
Intercepts window.open / target="_blank" links (Wv2Browser routes them into prewarmed tabs, preserving POST bodies and headers). |
AccessWebview supports three complementary communication channels between JavaScript and Access VBA:
Register any VBA class instance before calling View_Navigate / View_NavigateToString:
Set m_bridge = New clsWv2AccessBridge
m_pane.View_AddHostObjectToScript "vba", m_bridgeJavaScript can invoke any Public Function, Public Sub, or Public Property on clsWv2AccessBridge:
// 1. Async Proxy (Recommended — returns a Promise without freezing UI animations)
const updatedJson = await window.chrome.webview.hostObjects.vba.AddTask("Audit Q4", "Finance", "High");
// 2. Sync Proxy (Blocks JS until VBA returns; avoid calling EvalSync back into the same pane!)
const pong = window.chrome.webview.hostObjects.sync.vba.Ping("Hello");DAO Performance Best Practice in Split Access Databases:
When your Access front-end links to a shared network back-end.accdb, keep a persistent back-endDAO.Databasehandle open in your data service (clsDb/OpenDatabase(backEndPath)) and run SQL /OpenRecordsetagainst that back-end handle inside your bridge methods rather thanCurrentDblinked tables. Combined withhostObjects.vba, DAO reads/writes complete in < 10–80 ms with zero timer-polling latency.
Ideal for fire-and-forget notifications, streaming progress updates, or decoupled command buses:
-
VBA -> JS (
View_PostWebMessageAsString):m_pane.View_PostWebMessageAsString "{""event"":""recordSaved"",""id"":42}"window.chrome.webview.addEventListener('message', (ev) => { const msg = JSON.parse(ev.data); console.log('Pushed from Access:', msg); });
(Ensure the page has finished
NavigationCompletedor sent a"ready"message first; messages sent before JS registers its listener are dropped by WebView2.) -
JS -> VBA (
window.chrome.webview.postMessage):window.chrome.webview.postMessage(JSON.stringify({ cmd: 'openReport', name: 'rptInvoice' }));
Private WithEvents m_pane As Wv2Pane Private Sub m_pane_WebMessageReceived(ByVal messageText As String, ByVal messageJson As String) ' messageText is populated when JS passes a String; messageJson is always populated as JSON! Debug.Print "Received from JS: " & messageText End Sub
Wv2Pane.EvalSync(jsExpr, Optional timeoutSec = 5) wraps jsExpr inside a try { ... } catch + JSON.stringify(...) envelope, dispatches ICoreWebView2::ExecuteScript, pumps DoEvents until HK_ExecuteScriptCompleted arrives for that callbackId, unescapes the returned JSON string (including < \u003C escapes and UTF-16 surrogate pairs), and sets LastEvalOk / LastEvalError:
Dim countStr As String
countStr = p.EvalSync("document.querySelectorAll('.task-row').length")
If p.LastEvalOk Then
Debug.Print "Rendered rows: " & CLng(countStr)
Else
Debug.Print "Eval failed: " & p.LastEvalError
End IfCritical Re-Entrancy Rule (
m_inCallbackGuard):
Never callEvalSync,WaitFor, orWv2Elementmethods synchronously inside aWebMessageReceivedorNavigationCompletedevent handler. WebView2 holds its callback thread untilHandler_Invokereturns, so blocking inside the handler forExecuteScriptCompletedwould deadlock.Wv2Panedetectsm_inCallback > 0and returns immediately withLastEvalError = "in-callback". If you need to runEvalSyncin response to an event, defer it by 10 ms viaSafeTimeror the Access form'sMe.TimerInterval = 10(Form_Timer).
Wv2Pane injects a self-healing element registry (window.__wv2Reg) tagged with a per-document generation token ('g' + Date.now() + '-' + Math.random()). VBA receives lightweight integer handles wrapped in Wv2Element instances—eliminating CSS/JS quote-escaping bugs and automatically detecting stale elements after page navigations.
| Method / Property | Return Type | Description |
|---|---|---|
GetElementById(elementId) |
Wv2Element |
Finds #elementId (waits up to ImplicitWaitSec if > 0; returns Nothing if absent). |
QuerySelector(selector) |
Wv2Element |
Finds first matching CSS selector (Nothing if not found; check LastEvalOk to distinguish "not found" from errors). |
QuerySelectorAll(selector, [maxCount=200]) |
Collection |
Returns a 1-based Collection of Wv2Element objects (never Nothing, even when Count = 0). |
WaitFor(selector, [timeoutSec=10]) |
Wv2Element |
Polls until selector exists in the DOM or timeoutSec expires. Note: WaitFor returns an object—check If p.WaitFor("#id", 10) Is Nothing Then! |
WaitGone(selector, [timeoutSec=10]) |
Boolean |
Polls until selector disappears from the DOM (ideal for loading spinners/overlays). |
ImplicitWaitSec |
Single |
Opt-in automatic wait duration (default 0) applied to QuerySelector and GetElementById. |
| Member | Type | Description |
|---|---|---|
.TagName |
String (Get) |
Uppercase tag name (e.g., "INPUT", "BUTTON"). |
.InnerText / .InnerHTML |
String (Get) |
Reads rendered text or inner HTML markup. |
.value |
String (Get/Let) |
Reads or sets form control values. React/Vue-safe: invokes the native HTMLInputElement / HTMLTextAreaElement / HTMLSelectElement prototype value setter and dispatches bubbling input + change events. |
.Click() |
Boolean |
Calls .click() on the element (True if the element was still live in the current DOM generation). |
.GetAttribute(name) / .SetAttribute(name, val) |
String / Boolean |
Reads or updates HTML attributes. |
.IsStale |
Boolean (Get) |
True if the page navigated or the element was removed from the registry. |
.LastOk / .LastError |
Boolean / String |
Status of the most recent operation on this element ("", "stale", "in-callback", etc.). |
Modern SPAs update via fetch(), XMLHttpRequest, and microtask DOM mutations without firing NavigationCompleted. Wv2Pane includes an auto-injected SPA probe:
p.WaitSettled([timeoutSec=10], [quietMs=500]) As Boolean— Installs/verifies the in-pagefetch+XHR+MutationObserverprobe and waits until in-flight network requests hit0(excluding requests older thanStaleInflightMs, default15000 ms) and no non-ignored DOM mutations occur forquietMs.- Explicit Signals (Arm Before Clicking):
p.ArmContentSignal(cssSelector)—WaitSettledwill not declare success until text insidecssSelectorchanges.p.ArmNetworkSignal(urlSubstring)— Waits until at least one matchingfetch/XHRcompletes.p.ArmUrlSignal(urlFragment)— Waits untillocation.hrefcontainsurlFragment.
- Noise Filtering:
p.AddIgnoreNetwork("analytics")andp.IgnoreSelectors = ".clock, .toast"exclude background telemetry or ticking UI timers from blockingWaitSettled.
Wv2Pane can capture live HTTP/HTTPS traffic (WebResourceRequested + ICoreWebView2_2::WebResourceResponseReceived + GetContent)—acting like a programmable F12 Network tab inside Access VBA:
' 1. Configure capture BEFORE navigating so the initial DOCUMENT request is recorded
p.NetDetailOn = True ' Capture request headers & request body (IStream)
p.NetRespBodyOn = True ' Asynchronously capture decompressed response body
p.NetDetailUriFilter = "/api/" ' Optional substring filter for heavy detail capture
p.NetCaptureStart ' Default contexts: DOCUMENT, XML_HTTP_REQUEST, FETCH
p.View_Navigate "https://httpbingo.org/get"
p.WaitFor "pre", 10
' 2. Inspect captured entries (1..p.NetLogCount)
Dim i As Long
For i = 1 To p.NetLogCount
Debug.Print p.NetLogLine(i) & " -> HTTP " & p.NetLogStatus(i)
Debug.Print p.NetDetailHeaders(i)
Debug.Print p.NetDetailRespBody(i)
Next i
p.NetCaptureStopImportant Network Capture Guarantees:
- Non-Destructive Request Body Reading: Reading
ICoreWebView2WebResourceRequest::get_Contentadvances the liveIStreamcursor;Wv2Paneautomatically callsIStream::Seek(0, STREAM_SEEK_SET, NULL)afterward soPOSTbodies are never truncated on the wire. - Automatic Secret Redaction:
NetRedactdefaults toTrue, maskingCookie,Authorization,Proxy-Authorization, andSet-Cookieheaders in output logs (AddRedactHeaderadds custom headers). - Virtual Host Traffic Note: Requests served locally via
SetVirtualHostNameToFolderMappingbypass Chromium's network stack and therefore do not appear inWebResourceRequested(externalhttps:///http://127.0.0.1calls do).
Wv2Browser(src/Wv2Browser.cls): Manages a sharedWv2Environmentand a 1-basedCollectionofWv2Panetabs sharing a single hostHWND. RaisesTabAdded,TabClosed,ActiveChanged,TabTitleChanged, andTabUrlChangedevents.- POST-Preserving Popup Capture (
NewWindowMode = 2): Prewarms a hidden backgroundWv2Pane(PREWARM_DELAY_MS = 1500 msafterInit) and hands itsICoreWebView2*pointer directly toICoreWebView2NewWindowRequestedEventArgs::put_NewWindow, preservingPOSTpayloads, cookies, andSec-Fetch-Userheaders when sites open new windows. - Always call
m_browser.ShutdowninForm_Unloadto break theWv2Browser <-> Wv2Paneback-reference before settingm_browser = Nothing.
- POST-Preserving Popup Capture (
SafeTimer(src/SafeTimer.cls) &LibTimers(src/LibTimers.bas):
Replaces the upstream ExcelTimerForm.frm(MSForms.UserForm) with a lightweight Win32 message-only window (CreateWindowExW(..., "STATIC", ..., hWndParent:=HWND_MESSAGE)whereHWND_MESSAGE = -3) and cleans up deterministically viaKillTimer+DestroyWindowinClass_Terminate.LibTimers.GetTimerProcpatches VBE7'sEntryPointstub on bothx64(+55) andx86(+22, plus+30patched toRET 0x0010for 4-argumentTIMERPROCBreak-mode safety).
| Subsystem | 64-Bit (Win64) Behavior |
32-Bit (x86) Behavior & AccessWebview Guarantee |
|---|---|---|
WebView2Loader.dll Bitness |
Loads 64-bit C:\Program Files\Microsoft Office\root\Office16\WebView2Loader.dll |
Loads 32-bit C:\Program Files (x86)\Microsoft Office\root\Office16\WebView2Loader.dll (undecorated __stdcall exports; zero Alias changes needed). |
VBE7.DLL EntryPoint Stub |
91-byte stub; EbMode at +37, target immediate at +55, C2 00 00 (RET) |
33-byte stub; EbMode at +10, target immediate at +22, Break-mode epilogue at +28 patched from C2 00 00 to C2 0C 00 (RET 12) so Break mode never corrupts ESP. |
| Callback Machine-Code Thunk | 74-byte MS x64 ABI thunk (RCX, RDX, R8, R9 + [RSP+0x20] retval pointer) |
46-byte __stdcall thunk (CMP [pRegionBase], 1 -> PUSH 0 retval slot -> pushes &retval, arg2, arg1, this, pSelfObj -> CALL Handler_Invoke -> POP EAX -> RET 0x000C). |
ICoreWebView2Controller::put_Bounds(RECT) |
MS x64 ABI passes 16-byte RECT by pointer in RDX (VarPtr(bounds)) |
Win32 x86 __stdcall passes 16-byte RECT by value on the stack as 4 Longs (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom). Passing VarPtr on x86 produced 0x0 bounds! |
EventRegistrationToken (remove_*) & IStream::Seek |
8-byte int64 passed in single 64-bit register |
Stored as 8-byte Currency (0@, vbCurrency) so DispCallFunc pushes all 8 bytes onto the x86 stack by value while VarPtr(token) remains valid for [out] EventRegistrationToken*. |
ComCallbackHandler VTable Slot 7 |
Public Function Handler_Invoke placed after Friend members in upstream |
Moved Handler_Invoke to the top of ComCallbackHandler.cls above all Friend procedures so slot 7 is strictly Handler_Invoke in Access VBE. |
ICoreWebView2Environment VTable |
3 = CreateCoreWebView2Controller, 4 = CreateWebResourceResponse, 5 = get_BrowserVersionString |
Verified against Microsoft.Web.WebView2.Core.dll metadata: get_BrowserVersionString is vtable index 5 (calling slot 4 with 1 arg faults combase.dll on x86 stack mismatch). |
Hex GUID Parsing (HexStrToLong) |
Used CLngLng("&H" & s) |
Uses CLng("&H" & s) (without trailing &, which VBA rejects inside CLng() string parsing). |
Deep userDataFolder Creation |
Upstream EnsureFolder only created 1 parent level |
Recursive EnsureFolder creates arbitrary nested paths such as %LOCALAPPDATA%\AccessWebview\UserData. |
| Feature / Requirement | Access 365 EdgeBrowserControl (acEdgeBrowser) |
AccessWebview (WebView2Loader.dll + DispCallFunc) |
|---|---|---|
| External Installation / Registry Admin | None | None |
| Access 2016 / 2019 / 2021 / LTSC Support | Not available (Access 365 Current Channel only) | Supported anywhere Office + Edge WebView2 Runtime exist |
JS -> VBA Push (postMessage) |
Blocked (requires Form_Timer + RetrieveJavascriptValue queue polling) |
Native WebMessageReceived event (instant push, 0% idle CPU) |
Direct JS -> VBA Object RPC (hostObjects) |
Not exposed | Full chrome.webview.hostObjects.vba.* (async & sync) |
| Local Multi-File SPA Hosting | Requires https://msaccess/C:\... URL rewriting + MSysResources table |
SetVirtualHostNameToFolderMapping (https://appassets.access.local/) — zero MSysResources rows, full ES modules & pushState |
| External Link / Domain Whitelist | Enforced (MSysResources opens unwhitelisted URLs in external Edge) |
Full programmatic control via NavigationStarting / NewWindowRequested |
F12 DevTools & Custom userDataFolder |
Restricted / opaque | Full control (View_OpenDevToolsWindow, per-app userDataFolder) |
| Network Header & Body Capture | Not available | Built-in (NetCaptureStart, NetDetailOn, NetRespBodyOn) |
Immediate Window (Debug.Print) output scrolls rapidly during EvalSync polling or network capture. Wv2Log writes sequenced, timestamped UTF-8 logs to %APPDATA%\Wv2Browser\logs\wv2_YYYYMMDD_HHNNSS.log (retaining the latest 20 files automatically):
Wv2Log.LogStart
Wv2Log.LogLevel = LOG_DEBUG ' LOG_ERROR=1, LOG_WARN=2, LOG_INFO=3, LOG_DEBUG=4
Wv2Log.LogEcho = False ' Suppress Debug.Print echo for maximum speed
Debug.Print Wv2Log.LogPath ' Inspect active UTF-8 log file path
' ... run automation ...
Wv2Log.LogStopOpen AccessWebview.accdb, press Ctrl+G, and run the four verification stages in modWv2AccessHost:
? VerifyStep1_MockThunks()
' PASS: Mock QI + AddRef + Release + VBE7/MachineCode Thunk Invoke all succeeded!
? VerifyStep2_RealEnvironment()
' PASS: Real WebView2 Environment created via Office16\WebView2Loader.dll! Runtime=155.0.4283.45
? VerifyStep3_FullSpaAndBridge()
' PASS | Badge=[Microsoft Access 16.0.20430 (x86)] | Tasks: 4 -> 5 | LastPostMessage=[hello-from-webview2-js] | Url=https://appassets.access.local/index.html
? VerifyStep4_ResizeSurvival()
' PASS | Init="960x592" -> Shrink="720x432" -> Grow="1120x708" -> Max="1534x752" -> Restore="1120x708"- Do Not Step (
F8) Through the Async Init Burst orEvalSyncLoops:
While the 33-byte/91-byteVBE7EntryPointstub safely suppresses callbacks once VBE is already in Break mode (EbMode = 2), hitting a breakpoint in the microsecond between the stub'sEbModecheck andHandler_Invokeduring heavy WebView2 startup can faultMSACCESS.EXE. Place breakpoints afterInitSpacompletes or inspect behavior viaWv2Log. - Access VBE Cached P-Code After External Binary Edits:
Access.accdbfiles store both compressed VBA source and compiled p-code streams. If you edit modules externally (e.g., via XLIDE while Access is closed), run Debug -> Compile (or/decompile+ Compile) in Access so Access regenerates p-code from the updated source. - Keep
userDataFolderon Local Disk (%LOCALAPPDATA%):
Even whenAccessWebview.accdbandspa\live on a UNC/SMB network share (K:\...), always pointuserDataFolderto a local path such asEnviron$("LOCALAPPDATA") & "\MyApp\WebView2"(GetDefaultUserDataFolder()). Chromium's profile lock/SQLite cache files perform poorly or fail to lock over SMB shares. - Access/VBA Naming & Module Editing Conventions:
- Keep
Option Explicitat the top of every module, class, and form. - Never insert procedures above
Handler_InvokeinComCallbackHandler.cls(must stay vtable slot 7) or aboveStartTimer/TimerProcinSafeTimer.cls(must stay vtable slots 7 & 8). - Avoid Access/VBA/JET reserved words (
Name,Value,Date,Count,Index,Form,Section,Table) for new public identifiers.
- Keep
