Edge WebView2 Object Plugin

Description

The Edge WebView2 object lets you display a web site on the page or dialog, just like it would appear in the Chromium-based Edge web browser. It does this by taking advantage of the Microsoft Edge WebView2 control that needs to be present on the target system.
Specifically, it embeds this control directly into your AutoPlay application at run time. This essentially places the Edge rendering engine on your page and uses it to display HTML in your application.
The end result is pretty much the same as what you would see in Edge itself, except that the desktop browser interface is not visible. Therefore it looks like the web page is built right into your application. You can use it to display online web content on the Internet, or to display locally stored web pages directly off a CD-ROM (or the user's hard drive).

Object

Name

The name that is used to identify this object.

URL

The URL (or full path and filename) of the initial web page to display. This can be an HTML file, or any other type of file that can be viewed in a web browser. Click the browse button to select a file.

Events

On Navigate

The actions that will be performed whenever the URL changes (when it starts to navigate to a new page) in the Edge object. Click the edit button to open the script editor.

On Loaded

The actions that will be performed whenever the URL being navigated to has finished loading. Click the edit button to open the script editor.

Actions

Edge.Back (string ObjectName);

Description:

Navigates one page back in a Edge object.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.Back("WebView");

Edge.Forward (string ObjectName);

Description:

Navigates one page forward in a Edge object.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.Forward("WebView");

Edge.GetPos (string ObjectName);

Description:

Returns the X and Y page or dialog coordinates of a Edge object in pixels. This coordinate refers to the upper left hand corner of the object's bounding box relative to the page or dialog.

Note: The upper left hand corner of a page or dialog has X and Y coordinates of 0.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

(table) A table containing the object's current coordinates, indexed by values X and Y. If the object cannot be found, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

local tPos = Edge.GetPos("WebView");
Dialog.Message("Position", "X=" .. tPos.X .. ", Y=" .. tPos.Y);

Edge.GetProperties (string ObjectName);

Description:

Returns a table containing the properties of a Edge object.

ObjectName:

(string) The name of the Edge object.

Returns:

(table) A table containing the Edge object's properties, indexed by the following keys:

If the object cannot be found, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- get the currently loaded URL
sURL = Edge.GetProperties("WebView").URL;

-- Open the url in an external web browser
File.OpenURL(sURL, SW_SHOWNORMAL);

Edge.GetSize (string ObjectName);

Description:

Returns the pixel dimensions of a Edge object.

ObjectName:

(string) The name of the Edge object.

Returns:

(table) A table containing the object's pixel dimensions, indexed by values "Width" and "Height". If the object cannot be found, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

local tSize=Edge.GetSize("WebView");
Dialog.Message("Size", "Width=" .. tSize.Width .. ", Height=" .. tSize.Height);

Edge.GetURL (string ObjectName);

Description:

Gets the URL that is currently displayed in a web object.

Note: If the web object is displaying a local file, this action will return the full path to that file in the standard URL format, i.e. file:/// followed by the full path to the file.

ObjectName:

(string) The name of the Edge object.

Returns:

(string) The URL of the file that is currently displayed in the Edge object. If an error occurs, a blank string "" is returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

local sURL=Edge.GetURL("WebView");
Dialog.Message("URL", sURL);

Edge.IsEnabled (string ObjectName);

Description:

Returns true if a specific Edge object is enabled, or false if it's disabled.

Note: When a Edge object is disabled, it doesn't respond to the user at all. The document cannot be clicked, zoomed or scrolled.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

(boolean) True if the Edge object is enabled, false if it is disabled. If an error occurs, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- toggle the Edge object from enabled to disabled and vice-versa
Edge.SetEnabled("WebView", not Edge.IsEnabled("WebView"));
if Edge.IsEnabled("WebView") then
   Input.SetText("Status", "WebView is enabled");
else
   Input.SetText("Status", "WebView is disabled");
end

Edge.IsSilent (string ObjectName);

Description:

Returns true if a specific Edge object is silent, or false if it's not.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

(boolean) True if the Edge object is silent, false if it is not. If an error occurs, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

local bRes = Edge.IsSilent("WebView");

Edge.IsVisible (string ObjectName);

Description:

Returns true if a specific Edge object is visible, or false if it's not.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

(boolean) True if the Edge object is visible, false if it is hidden. If an error occurs, nil will be returned. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- toggle state from visible to hidden and vice-versa
Edge.SetVisible("WebView", not Edge.IsVisible("WebView"));
if Edge.IsVisible("WebView") then
   Input.SetText("Status", "WebView is visible");
else
   Input.SetText("Status", "WebView is hidden");
end

Edge.LoadHTML (string ObjectName, string HTML);

Description:

Loads a string of HTML into a Edge object. In order for the action to succeed the Edge object must have a valid window handle. This means that the object must be visible and that this action should happen after the page's "On Show" event.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

HTML:

(string) The HTML that will be loaded into the Edge object.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.LoadHTML("WebView", "<html><body><p>This is a test document.</p></body></html>");

Edge.LoadURL (string ObjectName, string URL);

Description:

Loads a local file or web-based URL into a Edge object.

Note: You cannot load a file or URL into a disabled web object. You must enable the object before loading the URL using the Web.SetEnabled action.

Note: If you want to use a named anchor on a relative path, it will fail. You must use the full path in order for this to work. For example, the following will not work:

Edge.LoadURL("Web1", "AutoPlay\\Docs\\index.html#news");

It must be specified as:

Edge.LoadURL("Web1", _SourceFolder.."\\AutoPlay\\Docs\\index.html#news");

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

URL:

(string) The URL for the web page, or the path to the local file.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.LoadURL("WebView", "https://www.indigorose.com");

Edge.Print (string ObjectName);

Description:

Allows to print the web page that is currently displayed in a Edge object. This action will open the "Print" dialog of the Edge browser, allowing to select printer, paper size and other settings.

ObjectName:

(string) The name of the Edge object.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.Print("WebView");

Edge.Refresh (string ObjectName);

Description:

Reload the currently loaded page in the Edge object.

Note: This is just like clicking the "Refresh" button in the browser to reload the current web page, or pressing the F5 key.

ObjectName:

(string) The name of the Edge object.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.Refresh("WebView");

Edge.SetEnabled (string ObjectName, boolean Enabled);

Description:

Sets the enabled/disabled state of a Edge object.

Note: When a Edge object is disabled, it doesn't respond to the user at all. The document cannot be clicked, zoomed or scrolled.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Enabled:

(boolean) Whether to make the Edge object enabled or disabled.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- toggle the Edge object from enabled to disabled and vice-versa
Edge.SetEnabled("WebView", not Edge.IsEnabled("WebView"));
if Edge.IsEnabled("WebView") then
   Input.SetText("Status", "WebView is enabled");
else
   Input.SetText("Status", "WebView is disabled");
end

Edge.SetPos (string ObjectName, number X, number Y);

Description:

Sets the X and Y pixel coordinates of a Edge object relative to the page or dialog.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

X:

(number) The new X pixel coordinate (horizontal position) to set for the Edge object. This is the X coordinate of the upper left hand corner of the object's bounding box relative to the page or dialog.

Y:

(number) The new Y pixel coordinate (vertical position) to set for the Edge object. This is the Y coordinate of the upper left hand corner of the object's bounding box relative to the page or dialog.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.SetPos("WebView", 10, 10);
local tPos = Edge.GetPos("WebView");
Dialog.Message("", "X=" .. tPos.X .. ", Y=" .. tPos.Y);

Edge.SetProperties (string ObjectName, table Properties);

Description:

Sets the properties of a Edge object.

ObjectName:

(string) The name of the Edge object.

Properties:

(table) A table containing the Edge object's properties, indexed by the following keys:

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

local tProps=Edge.SetProperties("WebView", { URL="https://google.com", Enabled=true, Visible=true, X=5, Y=5, Width=780, Height=500 });

Edge.SetSilent (string ObjectName, boolean Silent);

Description:

Sets whether or not the Edge object will display dialogs, including error dialogs.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Silent:

(boolean) Whether to make the web object silent.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

-- suppress any error messages
Edge.SetSilent("WebView");

Edge.SetSize (string ObjectName, number Width, number Height);

Description:

Sets the size of a Edge object.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Width:

(number) The new width of the Edge object in pixels.

Height:

(number) The new height of the Edge object in pixels.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.SetSize("WebView", 680, 450);
local tSize=Edge.GetSize("WebView");
Dialog.Message("", "Width=" .. tSize.Width .. ", Height=" .. tSize.Height);

Edge.SetVisible (string ObjectName, boolean Visible);

Description:

Sets the visibility of a Edge object.

Note: This option simply controls the visibility of Edge object. The object will continue to respond to actions even though it is hidden.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Visible:

(boolean) Whether to make the Edge object visible or invisible.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.SetVisible("WebView", not Edge.IsVisible("WebView"));
if Edge.IsVisible("WebView") then
   Input.SetText("Status", "WebView is visible");
else
   Input.SetText("Status", "WebView is hidden");
end

Edge.Stop (string ObjectName);

Description:

Stops a Edge object.

Note: This is just like clicking the "Stop" button in the web browser to interrupt the current download.

ObjectName:

(string) The name of the Edge object that you want to apply this action to.

Returns:

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

Example:

Edge.Stop("WebView");

Error Codes

210301 - Could not find object.
210302 - Incorrect object type.
210303 - Invalid URL.
210304 - Cannot go back.
210305 - Cannot go forward.
210306 - Unable to call Lua function.
210307 - Cannot find Lua function.
210308 - Unable to find object window.
210309 - Cannot print current document.

Change Log

2.0.0.0

Additional Information

Author:

Ulrich Peters
upeters@mindquake.com.br

Copyright:

The Edge WebView2 Object plugin is copyright © 2021 MindQuake Serviços de Informática.

Website:

https://www.mindquake.com.br

Documentation and SDK code:

Microsoft Edge WebView2
Getting started with WebView2
Reference (WebView2 Win32 C++)


Copyright © 2021 MindQuake Serviços de Informática.
All Rights Reserved.