Class: Webview

Webview(debug, target)

Class representing a Webview.

Constructor

new Webview(debug, target)

Create a webview.

Parameters:
Name Type Default Description
debug boolean false

enable DevTools and other debug features.

target null

the destination window handle. set it to null if you want to create a new window

Source:

Classes

Webview

Members

unsafeHandle

An unsafe pointer to the webview

Source:

unsafeWindowHandle

An unsafe pointer to the webviews platform specific native window handle.
An unsafe pointer to the webviews platform specific native window handle. When using GTK backend the pointer is GtkWindow pointer, when using Cocoa backend the pointer is NSWindow pointer, when using Win32 backend the pointer is HWND pointer.

Source:

Methods

bind(name, fn)

Binds a Node.js callback so that it will appear under the given name as a global JS function in webview . Example: bind("sumInNodeJS",(webview, a,b) => { return a+b; }); in webview browser, you should call await sumInNodeJS(1,2) and get 3

Parameters:
Name Type Description
name

the name of the global browser's JS function

fn

the callback function which receives the parameter and return the result to Webview. Any exception happened in Node.js here will reject the Promise instead of crash the program.

Source:

bindRaw(name, fn)

Binds a native NodeJS callback so that it will appear under the given name as a global webview's JS function. Callback receives an Array from browser's JS. Request string is a JSON array of all the arguments passed to the JS function.

Parameters:
Name Type Description
name

the name of the global browser's JS function

fn

the callback function receives the request parameter in webview browser and return the response(=[isSuccess,result]), both in JSON string. If isSuccess=false, it wll reject the Promise.

Source:

destroy()

Destroy the webview and close the native window. You must destroy the webview after [run]

Source:

dispatch(fn)

Posts a function to be executed on the main thread. It safely schedules the callback to be run on the main thread on the next main loop iteration.

Parameters:
Name Type Description
fn

the function to be executed on the main thread.

Source:

eval(js)

Evaluates arbitrary JS code in browser. Evaluation happens asynchronously, also the result of the expression is ignored. Use the bind function if you want to receive notifications about the results of the evaluation.

Parameters:
Name Type Description
js

the JS code

Source:

html(v)

Set webview HTML directly.

Parameters:
Name Type Description
v

the HTML content

Source:

init(js)

Injects JS code at the initialization of the new page. Every time the webview will open a new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload.

Parameters:
Name Type Description
js

the JS code

Source:

Navigates webview to the given URL URL may be a data URI, i.e. "data:text/text,...". It is often ok not to url-encode it properly, webview will re-encode it for you. Same as [navigate]

Parameters:
Name Type Description
url

the URL or URI

Source:

show()

Runs the main loop and destroy it when terminated. This will block the thread. Functions like setInterval won't work.

Source:

size(hints)

Updates the size of the native window. Accepts a WEBVIEW_HINT

Parameters:
Name Type Description
hints

can be one of NONE(=0), MIN(=1), MAX(=2) or FIXED(=3)

Source:

start()

Runs the main loop until it's terminated. After this function exits - you must destroy the webview. This will block the thread.

Source:

terminate()

Stops the main loop. It is safe to call this function from other background thread.

Source:

title(v)

Updates the title of the native window. Must be called from the UI thread.

Parameters:
Name Type Description
v

the new title

Source:

unbind(name)

Removes a callback that was previously set by webview_bind.

Parameters:
Name Type Description
name

the name of JS function used in webview_bind

Source: