WebView2 Essentials: Guides, Tips & Resources

WebView2 Essentials: Guides, Tips & Resources

Postby Otto » Wed Jan 10, 2024 6:56 pm

WebView2 Starts Multiple Edge Instances

It's normal for Microsoft's WebView2 to start multiple instances of the Microsoft Edge browser. WebView2 is built on the Edge Chromium platform and is designed to embed web technologies (HTML, CSS, and JavaScript) into native applications. When an application uses WebView2, it essentially opens a series of Edge browser processes in the background.

Each process serves a different purpose:

Browser Process: The main process that manages the user interface, handles navigation, and coordinates other processes.
Renderer Process: Handles the rendering of web content. There's usually a separate renderer process for each website or web app, which helps with security and stability.
Utility Process: Performs various tasks, such as networking or decoding media files.
GPU Process: Handles GPU-related tasks.
This architecture, where multiple processes run simultaneously, enhances performance, security, and stability. It ensures that if one part of your web content crashes or hangs, it doesn't bring down the entire application. This is a common approach in modern web browsers, including Chrome and Firefox, as well as in technologies that embed web content in applications, like Electron.

For developers, it's important to be aware of this behavior, especially when considering the resource usage of your application.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: WebView2 Essentials: Guides, Tips & Resources

Postby Otto » Wed Jan 10, 2024 7:01 pm

ChatGPT
Dokumentation webview2

The WebView2 control by Microsoft Edge allows you to embed web content (HTML, CSS, and JavaScript) in your native applications. It uses the Chromium-based Microsoft Edge as the rendering engine. This control is available for various frameworks and platforms including .NET/C#, WinRT/C#, Win32/C++, Core, WPF, Windows Forms, Unity/HoloLens 2, and more​​​​.

For developers working with WebView2, the following points are essential:

Features and APIs: WebView2 offers a range of features and APIs. The CoreWebView2 class provides web-specific functionalities such as networking, navigation, script handling, and HTML parsing and rendering. It includes methods like PostWebMessageAsJson, PostWebMessageAsString, and events like WebMessageReceived for interaction between the WebView2 control and the host application​​.

Getting Started: To start using WebView2 in WinForms applications, you need to follow several steps including setting up your development environment, initializing the WebView2 control, and handling navigation events. This involves coding in C# and using the CoreWebView2 namespace​​.

Properties and Methods: The WebView2 class in WPF, for instance, extends HwndHost and provides several properties like AllowExternalDrop, CanGoBack, CanGoForward, and Source. It allows access to the complete functionality of the underlying CoreWebView2 COM API​​.

Handling Asynchronous Operations: Since many WebView2 operations are asynchronous, it's important to handle these operations correctly in your application.

Error Handling: Some WebView2 and CoreWebView2 APIs may throw errors if invoked in certain ways, so it's important to be aware of these scenarios and handle them appropriately.

Interoperation with JavaScript: WebView2 exposes JavaScript APIs to HTML documents running within the control, supporting communication with the host application.

Documentation and Resources: For detailed information and specific implementation guidance, the WebView2 API Reference and WebView2 Documentation are valuable resources.

WebView2 is a versatile tool for developers looking to integrate web functionalities into their native applications, leveraging the capabilities of modern web technologies along with the benefits of native app development.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: WebView2 Essentials: Guides, Tips & Resources

Postby Otto » Wed Jan 10, 2024 7:05 pm

TWebView Class from FIVEWIN ChatGPT

The provided code is a class definition for TWebView, a custom class presumably designed to interface with a web view control, possibly for embedding web content in a desktop application. The class seems to be written in a language that resembles Harbour, a Clipper-compatible programming language. Let's break down the class and its methods:

Class: TWebView
This class appears to manage a web view control within a desktop application.

Data Members:
hWebView: Handle to the web view control.
bOnBind: A flag or callback related to binding JavaScript functions.
Methods:
New(nDebug, hWndParent): Constructor that creates a new web view instance. It takes debug settings and a parent window handle as arguments.

Navigate(cURL): Navigates the web view to a specified URL.

SetHtml(cHtml): Sets the HTML content of the web view.

Run(): Runs the web view.

Destroy(): Destroys the web view and cleans up resources.

Eval(cScript): Evaluates a JavaScript script in the context of the web view.

Init(cScript): Initializes the web view with a JavaScript script.

GetWindow(): Retrieves the window handle of the web view.

Bind(cName, pFunction): Binds a native function to a JavaScript function in the web view.

Center(): Centers the web view window.

Unbind(cName): Unbinds a previously bound JavaScript function.

Return(cRequest, nBindResult, cFromPrgToJS): Handles the return value from a bound function.

SetTitle(cTitle): Sets the title of the web view window.

SetSize(nWidth, nHeight, nHints): Sets the size of the web view window with optional size hints.

Print(): Invokes the print function of the web view.

SetParent(oWnd): Sets the parent window of the web view.

SetUserAgent(cUserAgent): Sets the user agent string of the web view.

Terminate(): Terminates the web view process.

Additional Functions
Bind(cName, pFunction) (Outside Class): A method for binding functions, with a default function WV_SENDTOFWH().

Destroy() (Outside Class): A method for destroying the web view, managing the aWebViews array.

WebView(cHtml, cTitle): A function to create, display, and destroy a web view with specific HTML content and title.

WebView_GetValues(cCalls, cJsonResult, hWebView): A function for retrieving values from the web view, possibly used in callbacks or bindings.

Notes:
The code seems to manage an array aWebViews to keep track of web view instances.
The usage of inline C-like functions (e.g., WebView_Create, SetWindowPos) suggests integration with lower-level system APIs or another library for web view control.
The class design is focused on interaction between the native application and the web view, providing functionalities like navigation, script execution, and event handling.
This class provides a comprehensive interface for embedding and controlling a web browser within a desktop application, likely tailored for the specific needs of the application it's designed for.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 57 guests