DEV Community

Cover image for WPF WebView2

WPF WebView2

John Peters
Lit-Html or Svelte?
・2 min read

The new Chrome based (Edge) browser wrapper named WebView2 (still not fully baked) is coming.

WebView2 will finally allow WPF and other applications to embed a fully functional WebBrowser.

Current State
It looks to me as if the architecture is similar to the Chrome Extension Architecture. Why? There's currently no direct way to access the DOM.

This is true in building Chrome Extensions too. The new Manifest Version 3 introduced the use of Service Workers which is middleware to the actual DOM. Direct DOM Access is gone for good.

Shouldn't be a problem right? As it turns out, like all things new in the IT world, I just can't seem to figure out how to do something easy like issue a query to the DOM for parsing element ids, names, innerText etc. All this means is that it's either too new still or I need to try harder.

I tried WebView2 recently and found that it's even harder to understand how to do a DOM Query. I just couldn't get anything to fly despite loading the sample and trying many different approaches.

This did make me think that this stuff is still too new and there doesn't seem to be enough examples yet. Or, they intentionally don't want DOM Queries to happen.

I don't think Electron will escape this either because they too embed Chrome.

We'll see.

But maybe, this Version 3 Manifest change is the culprit...

  file: 'content-script.js'
Enter fullscreen mode Exit fullscreen mode

We can no longer execute Javscript strings, we have to instead execute a file which is contained in the bundle.

They've also introduced a new 'function' property as show here in the file for the code above:

function showAlert() {

  function: showAlert
Enter fullscreen mode Exit fullscreen mode

This appears to be the new normal.
My only question now is "Can the new Service Worker just use regular Document syntax for the query, or is there some other way. And how does the worker return the message?

Here's another link for Service Workers

JWP2021 WPF WebView2

Discussion (0)