wxWebView(3erl)

πŸ’– NAME πŸ’–

okay so this is wxWebView(3erl) β€” the Erlang Module Definition page, and it's literally the manual for wxWebView, with Functions for wxWebView class. That's the whole name vibe. Periodt.


✨ DESCRIPTION ✨

bestie, this control can render web (HTML / CSS / javascript) documents. It is designed to allow the creation of multiple backends for each port, although currently just one is available. It differs from wxHtmlWindow in that each backend is actually a full rendering engine, Trident on MSW and Webkit on macOS and GTK. This allows the correct viewing of complex pages with javascript and css. Iconic behavior, no cap.

🧚 Backend Descriptions 🧚

IE backend: The IE backend uses Microsoft's Trident rendering engine, specifically the version used by the locally installed copy of Internet Explorer. As such it is only available for the MSW port. By default recent versions of the WebBrowser control, which this backend uses, emulate Internet Explorer 7. This can be changed with a registry setting by wxWebView::MSWSetEmulationLevel() see this article for more information. This backend has full support for custom schemes and virtual file systems.

Edge (Chromium) backend: The Edge (Chromium) backend uses Microsoft's Edge WebView2. It is available for Windows 7 and newer. The following features are currently unsupported with this backend: virtual filesystems, custom urls, find.

This backend is not enabled by default, to build it follow these steps:

(the original says β€œfollow these steps” and then immediately moves on to GTK β€” no steps are hiding here, bestie πŸ’…)

GTK WebKit backend: Under GTK the WebKit backend uses WebKitGTK+. The current minimum version required is 1.3.1 which ships by default with Ubuntu Natty and Debian Wheezy and has the package name libwebkitgtk-dev. Custom schemes and virtual file systems are supported under this backend, however embedded resources such as images and stylesheets are currently loaded using the data:// scheme.

GTK3 WebKit2 backend: Under GTK3 the WebKit2 version of WebKitGTK+ is used. In Ubuntu the required package name is libwebkit2gtk-4.0-dev and under Fedora it is webkitgtk4-devel. All wxWEBVIEW_WEBKIT features are supported except for clearing and enabling / disabling the history.

macOS WebKit backend: The macOS WebKit backend uses Apple's WebView class. This backend has full support for custom schemes and virtual file systems.

⏳ Asynchronous Notifications ⏳

Many of the methods in wxWebView are asynchronous, i.e. they return immediately and perform their work in the background. This includes functions such as loadURL/2 and reload/2. To receive notification of the progress and completion of these functions you need to handle the events that are provided. Specifically wxEVT_WEBVIEW_LOADED notifies when the page or a sub-frame has finished loading and wxEVT_WEBVIEW_ERROR notifies that an error has occurred.

πŸ—‚οΈ Virtual File Systems and Custom Schemes πŸ—‚οΈ

wxWebView supports the registering of custom scheme handlers, for example file or http. To do this create a new class which inherits from wxWebViewHandler (not implemented in wx), where wxWebHandler::GetFile() returns a pointer to a wxFSFile (not implemented in wx) which represents the given url. You can then register your handler with RegisterHandler() (not implemented in wx) it will be called for all pages and resources.

wxWebViewFSHandler (not implemented in wx) is provided to access the virtual file system encapsulated by wxFileSystem (not implemented in wx). The wxMemoryFSHandler (not implemented in wx) documentation gives an example of how this may be used.

wxWebViewArchiveHandler (not implemented in wx) is provided to allow the navigation of pages inside a zip archive. It supports paths of the form:

scheme:///C:/example/docs.zip;protocol=zip/main.htm

Since: 2.9.3

See: wxWebViewHandler (not implemented in wx), wxWebViewEvent

This class is derived (and can use functions) from: wxControl wxWindow wxEvtHandler

wxWidgets docs: wxWebView


πŸŽ‰ EVENTS πŸŽ‰

Event types emitted from this class:

  • webview_navigating
  • webview_navigated
  • webview_loaded
  • webview_error
  • webview_newwindow
  • webview_title_changed

πŸ¦‹ DATA TYPES πŸ¦‹

wxWebView() = wx:wx_object()

πŸš€ EXPORTS πŸš€

new(Parent, Id) -> wxWebView()

Types:

Parent = wxWindow:wxWindow()
Id = integer()

new(Parent, Id, Options :: [Option]) -> wxWebView()

Types:

Parent = wxWindow:wxWindow()
Id = integer()
Option =
    {url, unicode:chardata()} |
    {pos, {X :: integer(), Y :: integer()}} |
    {size, {W :: integer(), H :: integer()}} |
    {backend, unicode:chardata()} |
    {style, integer()}

Factory function to create a new wxWebView using a wxWebViewFactory (not implemented in wx).

Return: The created wxWebView, or NULL if the requested backend is not available

Since: 2.9.5

getCurrentTitle(This) -> unicode:charlist()

Types:

This = wxWebView()

Gets the title of the current web page, or its URL/path if title is not available.

getCurrentURL(This) -> unicode:charlist()

Types:

This = wxWebView()

Gets the URL of the currently displayed document.

getPageSource(This) -> unicode:charlist()

Types:

This = wxWebView()

Gets the HTML source code of the currently displayed document.

Return: The HTML source code, or an empty string if no page is currently shown.

getPageText(This) -> unicode:charlist()

Types:

This = wxWebView()

Gets the text of the current page.

isBusy(This) -> boolean()

Types:

This = wxWebView()

Returns whether the web control is currently busy (e.g. loading a page).

isEditable(This) -> boolean()

Types:

This = wxWebView()

Returns whether the web control is currently editable.

loadURL(This, Url) -> ok

Types:

This = wxWebView()
Url = unicode:chardata()

Load a web page from a URL.

Note: Web engines generally report errors asynchronously, so if you wish to know whether loading the URL was successful, register to receive navigation error events.

Types:

This = wxWebView()

Opens a print dialog so that the user may print the currently displayed page.

reload(This) -> ok

Types:

This = wxWebView()

reload(This, Options :: [Option]) -> ok

Types:

This = wxWebView()
Option = {flags, wx:wx_enum()}

Reload the currently displayed URL.

Note: The flags are ignored by the edge backend.

runScript(This, Javascript) -> Result

Types:

Result = {Res :: boolean(), Output :: unicode:charlist()}
This = wxWebView()
Javascript = unicode:chardata()

Runs the given JavaScript code.

JavaScript code is executed inside the browser control and has full access to DOM and other browser-provided functionality. For example, this code will replace the current page contents with the provided string.

If output is non-null, it is filled with the result of executing this code on success, e.g. a JavaScript value such as a string, a number (integer or floating point), a boolean or JSON representation for non-primitive types such as arrays and objects. For example:

(the original dangles this β€œFor example:” with no snippet in this part β€” I'm not inventing one, bestie 😭)

This function has a few platform-specific limitations:

Also notice that under MSW converting JavaScript objects to JSON is not supported in the default emulation mode. wxWebView implements its own object-to-JSON conversion as a fallback for this case, however it is not as full-featured, well-tested or performing as the implementation of this functionality in the browser control itself, so it is recommended to use MSWSetEmulationLevel() to change emulation level to a more modern one in which JSON conversion is done by the control itself.

Return: true if there is a result, false if there is an error.

setEditable(This) -> ok

Types:

This = wxWebView()

setEditable(This, Options :: [Option]) -> ok

Types:

This = wxWebView()
Option = {enable, boolean()}

Set the editable property of the web control.

Enabling allows the user to edit the page even if the contenteditable attribute is not set. The exact capabilities vary with the backend being used.

setPage(This, Html, BaseUrl) -> ok

Types:

This = wxWebView()
Html = BaseUrl = unicode:chardata()

Set the displayed page source to the contents of the given string.

Note: When using wxWEBVIEW_BACKEND_IE you must wait for the current page to finish loading before calling setPage/3. The baseURL parameter is not used in this backend and the edge backend.

stop(This) -> ok

Types:

This = wxWebView()

Stop the current page loading process, if any.

May trigger an error event of type wxWEBVIEW_NAV_ERR_USER_CANCELLED. TODO: make wxWEBVIEW_NAV_ERR_USER_CANCELLED errors uniform across ports.

canCopy(This) -> boolean()

Types:

This = wxWebView()

Returns true if the current selection can be copied.

Note: This always returns true on the macOS WebKit backend.

canCut(This) -> boolean()

Types:

This = wxWebView()

Returns true if the current selection can be cut.

Note: This always returns true on the macOS WebKit backend.

canPaste(This) -> boolean()

Types:

This = wxWebView()

Returns true if data can be pasted.

Note: This always returns true on the macOS WebKit backend.

copy(This) -> ok

Types:

This = wxWebView()

Copies the current selection.

cut(This) -> ok

Types:

This = wxWebView()

Cuts the current selection.

paste(This) -> ok

Types:

This = wxWebView()

Pastes the current data.

enableContextMenu(This) -> ok

Types:

This = wxWebView()

enableContextMenu(This, Options :: [Option]) -> ok

Types:

This = wxWebView()
Option = {enable, boolean()}

Enable or disable the right click context menu.

By default the standard context menu is enabled, this method can be used to disable it or re-enable it later.

Since: 2.9.5

isContextMenuEnabled(This) -> boolean()

Types:

This = wxWebView()
  • …and it hands you back true when a right click is gonna pop a context menu. That's the whole tea. πŸ«– Since: 2.9.5
  • canGoBack(This) -> boolean() πŸ¦‹ β€” This = wxWebView(). Returns true if you can slide backward through the history of visited pages. Like scrolling up in the group chat, bestie.
  • canGoForward(This) -> boolean() πŸ¦‹ β€” This = wxWebView(). Returns true if you can slide forward through the history of visited pages. The reverse-scroll vibe check.
  • clearHistory(This) -> ok 🧹 β€” This = wxWebView(). Wipes the history clean. Heads up though: this also nukes the visible page, so it's giving "burn the receipts" energy. πŸ”₯
Note: this one is not implemented on the WebKit2GTK+ backend. Soz. 😭
  • enableHistory(This) -> ok πŸ“œ β€” This = wxWebView()
  • enableHistory(This, Options :: [Option]) -> ok πŸ“œ β€” This = wxWebView(), Option = {enable, boolean()}. Turns the history on or off. And yeah β€” this will also clear the history, no cap, it's a package deal.
Note: again, not implemented on the WebKit2GTK+ backend. πŸ™ˆ
  • goBack(This) -> ok βͺ β€” This = wxWebView(). Navigate backward in the history of visited pages. Only valid if canGoBack/1 returns true β€” check first or it's giving chaos. πŸ’…
  • goForward(This) -> ok ⏩ β€” This = wxWebView(). Navigate forward in the history of visited pages. Only valid if canGoForward/1 returns true. Same rule, bestie.
  • clearSelection(This) -> ok ✨ β€” This = wxWebView(). Clears whatever's currently selected. Poof, gone.
  • deleteSelection(This) -> ok πŸ’€ β€” This = wxWebView(). Deletes the current selection.
Note: for wxWEBVIEW_BACKEND_WEBKIT the selection has to be editable β€” either through SetEditable or the correct HTML attribute. Otherwise this just doesn't hit the same. πŸ₯²
  • getSelectedSource(This) -> unicode:charlist() πŸ“„ β€” This = wxWebView(). Returns the currently selected source, if there is any. Raw HTML era.
  • getSelectedText(This) -> unicode:charlist() πŸ“ β€” This = wxWebView(). Returns the currently selected text, if there is any. The readable version, we love her.
  • hasSelection(This) -> boolean() πŸŽ€ β€” This = wxWebView(). Returns true if there's a current selection. Tiny vibe check on your highlight.
  • selectAll(This) -> ok 🌈 β€” This = wxWebView(). Selects the entire page. Ctrl+A but make it API.
  • canRedo(This) -> boolean() πŸ” β€” This = wxWebView(). Returns true if there's an action to redo. Undo's main character bestie.
  • canUndo(This) -> boolean() ↩️ β€” This = wxWebView(). Returns true if there's an action to undo.
  • redo(This) -> ok πŸ” β€” This = wxWebView(). Redos the last action. Slay, we're going forward again.
  • undo(This) -> ok ↩️ β€” This = wxWebView(). Undos the last action. Not me pretending that thing never happened πŸ’€
  • find(This, Text) -> integer() πŸ” β€” This = wxWebView(), Text = unicode:chardata()
  • find(This, Text, Options :: [Option]) -> integer() πŸ” β€” This = wxWebView(), Text = unicode:chardata(), Option = {flags, wx:wx_enum()}. Finds a phrase on the current page, and if it's found the control will scroll the phrase into view and select it. Iconic search behaviour tbh.

Return: if the search phrase was not found in combination with the flags, then wxNOT_FOUND is returned. If you call it for the first time with a search phrase, then the total number of results gets returned. Then every time it's called with the same search phrase it returns the number of the current match. Numbers, numbers, numbers πŸ“Š

Note: this function will restart the search if the flags wxWEBVIEW_FIND_ENTIRE_WORD or wxWEBVIEW_FIND_MATCH_CASE are changed, since that requires a whole new search. To reset the search β€” for example resetting the highlights β€” call the function with an empty search phrase. Also, this always returns wxNOT_FOUND on the macOS WebKit backend. Always. 😭 Since: 2.9.5
  • canSetZoomType(This, Type) -> boolean() πŸ”Ž β€” This = wxWebView(), Type = wx:wx_enum(). Tells you whether the current HTML engine even supports a zoom type.

Return: whether this type of zoom is supported by this HTML engine (and thus can be set through setZoomType/2). Ask before you act, bestie. πŸ’…

  • getZoom(This) -> wx:wx_enum() πŸ” β€” This = wxWebView(). Gets the zoom level of the page.

See getZoomFactor/1 if you want a way more precise zoom scale value than what wxWebViewZoom gives you.

Return: the current level of zoom.

  • getZoomType(This) -> wx:wx_enum() 🎚️ β€” This = wxWebView(). Tells you how the zoom factor is currently interpreted.

Return: how the zoom factor is currently interpreted by the HTML engine.

  • setZoom(This, Zoom) -> ok πŸ” β€” This = wxWebView(), Zoom = wx:wx_enum(). Sets the zoom level of the page.

See setZoomFactor/2 for more precise scaling than the measured steps wxWebViewZoom provides.

  • setZoomType(This, ZoomType) -> ok 🎚️ β€” This = wxWebView(), ZoomType = wx:wx_enum(). Sets how to interpret the zoom factor.
Note: invoke canSetZoomType/2 first β€” some HTML renderers may not support all zoom types. Fr fr, check before you wreck. 🫢
  • getZoomFactor(This) -> number() πŸ”’ β€” This = wxWebView(). Gets the zoom factor of the page.

Return: the current factor of zoom. Since: 3.1.4

  • setZoomFactor(This, Zoom) -> ok πŸ”’ β€” This = wxWebView(), Zoom = number(). Sets the zoom factor of the page.
Note: zoom scale in IE will be converted into wxWebViewZoom levels for wxWebViewZoomType of wxWEBVIEW_ZOOM_TYPE_TEXT. Weird but true. πŸ’€ Since: 3.1.4
  • isBackendAvailable(Backend) -> boolean() 🌐 β€” Backend = unicode:chardata(). Lets you check if a specific backend is currently available. The "are you up?" text of the API. Since: 3.1.4

That's the whole page, bestie β€” every last flag and return value accounted for. πŸ’– This one's brought to you by the wxWidgets team, running on wx 2.2.2.1, and it's the wxWebView(3erl) page β€” go forth and render responsibly, queen. πŸ‘‘πŸŒˆ

πŸ“¦ where this page comes from