Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Deno
This package works with Deno
JSR Score100%
Downloads46/wk
Published2 years ago (0.9.0)

🌐 Deno bindings for webview, a tiny library for creating web-based desktop GUIs

Examples

Example 1

import { Webview } from "@webview/webview";

const html = `
  <html>
  <body>
    <h1>Hello from deno v${Deno.version.deno}</h1>
  </body>
  </html>
`;

const webview = new Webview();

webview.navigate(`data:text/html,${encodeURIComponent(html)}`);
webview.run();

Classes

c
Webview(
debugOrHandle?: boolean | Deno.PointerValue,
size?: Size | undefined,
window?: Deno.PointerValue | null
)
2 constructors

An instance of a webview window.

  • bind(
    name: string,
    callback: (...args: any) => any
    ): void

    Binds a callback so that it will appear in the webview with the given name as a global async JavaScript function. Callback arguments are automatically converted from json to as closely as possible match the arguments in the webview context and the callback automatically converts and returns the return value to the webview.

  • bindRaw(
    name: string,
    callback: (
    seq: string,
    req: string,
    arg: Deno.PointerValue | null
    ) => void
    ,
    arg?: Deno.PointerValue | null
    ): void

    Binds a callback so that it will appear in the webview with the given name as a global async JavaScript function. Callback receives a seq and req value. The seq parameter is an identifier for using Webview.return to return a value while the req parameter is a string of an JSON array representing the arguments passed from the JavaScript function call.

  • destroy(): void

    Destroys the webview and closes the window along with freeing all internal resources.

  • eval(source: string): void

    Evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also the result of the expression is ignored. Use bindings if you want to receive notifications about the results of the evaluation.

  • init(source: string): void

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

  • navigate(url: URL | string): void

    Navigates webview to the given URL. URL may be a data URI, i.e. "data:text/html,<html>...</html>". It is often ok not to url-encodeCString it properly, webview will re-encodeCString it for you.

  • return(
    seq: string,
    status: number,
    result: string
    ): void

    Returns a value to the webview JavaScript environment.

  • run(): void

    Runs the main event loop until it's terminated. After this function exits the webview is automatically destroyed.

  • size(unnamed 0: Size): void

    Sets the native window size

  • title(title: string): void

    Sets the native window title

  • unbind(name: string): void

    Unbinds a previously bound function freeing its resource and removing it from the webview JavaScript context.

  • unsafeHandle(): Deno.PointerValue

    UNSAFE: Highly unsafe API, beware!

  • unsafeWindowHandle(): Deno.PointerValue

    UNSAFE: Highly unsafe API, beware!

Functions

f
preload(): Promise<void>

Loads the ./WebView2Loader.dll for running on Windows. Removes old version if it already existed, and only runs once. Should be run on the main thread so that the unload gets hooked in properly, otherwise make sure unload gets called during the window.onunload event (after all windows are closed).

f
unload(): void

Unload the library and destroy all webview instances. Should only be run once all windows are closed. If preload was called in the main thread, this will automatically be called during the window.onunload event; otherwise, you may have to call this manually.

Interfaces

I

Window size

  • height: number

    The height of the window

  • hint: SizeHint

    The window size hint

  • width: number

    The width of the window

Type Aliases

T
v
SizeHint = SizeHint[keyof SizeHint]

Window size hints

  • FIXED: number
    No documentation available
  • MAX: number
    No documentation available
  • MIN: number
    No documentation available
  • NONE: number
    No documentation available

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@webview/webview

Import symbol

import * as mod from "@webview/webview";
or

Import directly with a jsr specifier

import * as mod from "jsr:@webview/webview";