Working with WebBrowser

What can WebBrowser support?

The WebBrowser control uses the Chromium Embedded Framework (CEF), an open source framework used in many applications to provide web browsing functionality. Therefore, the WebBrowser control can be used to create a Web browser that can communicate between the Web page and the PowerBuilder client.

The WebBrowser control:

  • Supports browsing web page that contains JavaScript

  • Supports accessing web page that requires basic or digest authentication

    The WebBrowser control will automatically display a login window for the user to enter the user name and password for authentication. If the authentication fails, this window will display again until the authentication is successful or the authentication operation is cancelled.

  • Supports browsing HTML and HTML5 pages

  • Supports browsing videos at common formats in web page (MPEG-4 ASP, H.264, and H.265 formats are unsupported)

  • Supports playing flash (with the flash plug-in installed by the user)

  • Supports printing web pages as PDFs and responding to the print events

  • Supports browsing web pages that support multiple languages

  • Supports the various HTTPS protocols

  • Supports the right-mouse context menus

  • Supports browsing a PDF file online

  • Supports web page zoom in/out

  • Supports browsing local files (including htm, gif, jpg, jpeg, png, swf, txt, c, cpp, pdf, etc.)

  • Supports responding to the error event from the server certificate

  • Supports dynamically configuring the file download location and proxy settings

And does not support:

  • callback of the popup window

  • cookie manipulation interface

  • request irrelevant to the browser

  • responding to the keyboard actions (such as F5)

  • receiving focus when the user tabs among controls within a window

  • searching within the web page

  • drag & drop in the web page

  • Google Developer tools

  • loading the local file from different origins via file:/// (you will have to use http or https)

For a complete list of properties/functions/events of the WebBrowser control, refer to the section called “WebBrowser control” in Objects and Controls.

Configuring WebBrowser

Use the global functions WebBrowserSet and WebBrowserGet to configure the path, user agent and proxy settings for the WebBrowser control.

Path settings:

  • CachePath -- The folder that stores the web page cache, cookies etc.

  • UserDataPath -- The folder that stores the user data dictionary.

  • DownloadPath -- The default download path.

User agent settings:

  • 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.

Proxy settings:

  • ProxyAuto -- Whether to use auto proxy detection. WebBrowser supports auto proxy detection, PAC (proxy auto configuration) file setting, and manual proxy settings. The priority order of the settings is: auto proxy detection > PAC file setting > manual proxy settings. By default the IE proxy is used.

  • ProxyPacUrl -- The URL of the server where the PAC file is located.

  • ProxyAddress -- The address of the proxy server.

  • ProxyPort -- The port of the proxy server.

  • ProxyUser -- The user name that will be authenticated by the proxy server.

  • ProxyPassword -- The password that will be authenticated by the proxy server.

Local file access:

  • allow-file-access-from-files -- Whether to allow access to the local files (XML etc.).

  • enable-media-stream -- Whether to allow access to the microphone or camera.

Defining user events for WebBrowser

You can define PowerBuilder user events for WebBrowser and then trigger the event in JavaScript. User events must be defined with only one string-type parameter and string-type return value (code example).

EventName (string parameter)

User events must be registered by RegisterEvent function before it can be triggered in JavaScript.

It is not allowed to call any other WebBrowser functions in the user event.

Packaging WebBrowser

If the WebBrowser control is used in the application, the developer needs to select the "WebBrowser Support" option in the PowerBuilder Runtime Packager to package the WebBrowser components (and the "pbcef" folder) into the PowerBuilder runtime installer.

WebBrowser control vs. Microsoft Web Browser OLE control

This new WebBrowser control has the following advantages over the Microsoft Web Browser OLE control:

  • Supports HTML5

  • Provides more control on download

  • Able to set the default URL

  • Shorter dot notation to access functions or properties

This new WebBrowser control has the following disadvantages compared to the Microsoft Web Browser OLE control:

  • Fewer options on the right-click popup menu

  • Does not support the web page document interface

  • Unable to get the current URL through properties or functions

For differences on properties/functions/events of WebBrowser control vs. Microsoft Web Browser OLE control, refer to the section called “WebBrowser control” in Objects and Controls.