WebBrowserSet

Description

Configures the settings for the WebBrowser control. The global settings are also configured.

Note that some settings must be set before the WebBrowser control is initialized. These settings should be set in the application Open event.

Syntax

WebBrowserSet (string n, string v)

Argument

Description

n

The name of the setting that is case insensitive. The setting can be:

Important

The following settings must be set before the window that contains the WebBrowser control is opened: RuntimeMode, FixedVersionRuntimePath, allow-file-access-from-files, UserDataFolder, Language, UserAgent, remote-allow-origins, and remote-debugging-port. It is recommended that you set them in the application Open event, or in any event that is triggered earlier than the window that contains the WebBrowser control is opened.

The remote-allow-origins, and remote-debugging-port settings should be used only when the application is in the debug mode. For optimal performance, please comment out these settings when the application is not in the debug mode.

If you have run the application (that includes the WebBrowser control) from PowerBuilder IDE, you may need to restart the application and the PowerBuilder IDE before the program can successfully initialize the WebBrowser control again.

  • RuntimeMode -- The distribution mode of WebView2 Runtime. This setting has a higher precedence than the setting in the IDE > Application properties dialog box.

  • FixedVersionRuntimePath -- The path of WebView2 Runtime Fixed Version. Both the relative path and absolute path are supported.

  • DownloadPath -- The default download path. Both the relative path and absolute path are supported. By default, the system default download path will be used, for example, "C:\Users\appeon\Downloads" in 64-bit Windows 10.

  • allow-file-access-from-files -- Whether to allow access to the local files (XML etc.). The value is "true" or "false" (the default). allow-file-access-from-files must be used with UserDataFolder, and each application must have its own UserDataFolder, otherwise WebBrowser may not work properly.

  • UserDataFolder -- The folder that stores user data. Both the relative path and absolute path are supported. The default user data folder is %temp%\PB250UDF in the development machine and %temp%\<appname>UDF at the client.

  • Language -- The language of WebBrowser control to be set.

  • UserAgent -- The User-Agent request header that contains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent. The default value of UserAgent cannot be obtained until the WebBrowser control is initialized and created.

  • remote-allow-origins -- Which origins or domains are allowed to access the resource on a server. A wildcard "*" indicates any origin or domain is allowed to access the requested source.

  • remote-debugging-port -- Whether to specify a port number that allows remote debugging of the current URL. When the remote debugging port is enabled, it allows developers to connect to the URL using a debugger and inspect its internal workings.

    To support the remote debugging:

    1. Enable remote debugging on the specified port number, by executing the following script in the application Open event:

    li_return = WebBrowserSet("remote-debugging-port", "8210")
    li_return = WebBrowserSet("remote-allow-origins", "*") 
    

    Every time when these scripts are executed, a unique page ID is generated. You can get and use this ID through the debugging APIs.

    2. Run the debugging APIs in Chrome or Edge browser. For example:

    Access the main page: http://localhost:8210

    Get the JSON string (which includes the page ID): http://localhost:8210/json

    Get the version information: http://localhost:8210/json/version

    Activate the page: http://localhost:8210/json/activate/{id}, for example, http://localhost:8210/json/activate/054A6021CB9DD4EDBDBFA55E4384EA38

    Close the page: http://localhost:8210/json/close/{id}

    Remote control: http://localhost:8210/devtools/inspector.html?ws=localhost:8210/devtools/page/{id}

    Here is the returned information when debugging www.appeon.com:


v

The value of the setting to be set.

  • When the name of the setting is "RuntimeMode", the following values can be specified:

    0 -- Use the WebView2 Evergreen Runtime.

    1 -- Use the WebView2 Runtime Fixed Version.

    2 -- Use the WebView2 Evergreen Runtime by default; if it does not exist, use the Fixed Version. If you modify this value, you must restart PowerBuilder IDE and the application for the value to take effect; and this value has a higher precedence than the setting in the IDE > Application properties dialog box.

  • When the name of the setting is "Language", this value is used to set the language in the UI of WebBrowser control, such as the context menu and the default dialog box. And it is also used in the accept-languages HTTP request header sent to the website.

    The format is language[-country] in which language is a two letter code in ISO 639 and country is a two character code in ISO 3166.

  • When the name of the setting is "UserDataFolder", this value is used to set the user data directory.


Return value

Integer.

Returns 1 if the function succeeds and a negative value if an error occurs. If any argument's value is null, the method returns null.

Examples

The following example configures the language settings for the WebBrowser control in the application Open event.

long ll_Ret

ll_Ret =WebBrowserSet("Language", "de-DE")

See also

WebBrowserGet