deno_webview
This project provides deno bindings for webview using the webview rust bindings. Webview is a tiny cross-platform library to render web-based GUIs for desktop applications. This project is still in an early stage of development and stability is sometimes questionable. The plugin should be compatible with MacOS, Linux and Windows. It has been tested on Windows and Xubuntu where it worked as expected using the latest versions of deno. The current goal of deno_webview is to provide high quality bindings to webview for creating light cross-platform applications using web technologies.
Example
Run the following with the -A
flag enabled to get the example shown above:
import { WebView } from "https://deno.land/x/webview/mod.ts";
const webview1 = new WebView({
title: "Multiple deno_webview example",
url: `data:text/html,
<html>
<body>
<h1>1</h1>
</body>
</html>
`,
width: 800,
height: 600,
resizable: true,
debug: true,
frameless: false
});
const webview2 = new WebView({
title: "Multiple deno_webview example",
url: `data:text/html,
<html>
<body>
<h1>2</h1>
</body>
</html>
`,
width: 800,
height: 600,
resizable: true,
debug: true,
frameless: false
});
await Promise.all([webview1.run(), webview2.run()]);
or just run the following in the terminal:
deno -A https://deno.land/x/webview/examples/multiple.ts
Docs
Docs can also be found here.
WebView
A WebView
instance
- WebView.constructor(args: { title?: string; url?: string; width?: number;
height?: number; resizable?: boolean; debug?: boolean; frameless?: boolean;
}): WebView
- Creates a new
WebView
instance
- Creates a new
- WebView.run(): Promise
- Runs the event loop to completion
- WebView.step(): boolean
- Iterates the event loop and returns
false
if the theWebView
has been closed
- Iterates the event loop and returns
- WebView.exit(): Void
- Exits the
WebView
- Exits the
- WebView.eval(js: string): Void
- Evaluates the provided js code in the
WebView
- Evaluates the provided js code in the
- WebView.setColor(color: { r: number; g: number; b: number; a: number; }):
Void
- Sets the color of the title bar to the provided RGBA value
- WebView.setTitle(title: string): Void
- Sets the window title
- WebView.setFullscreen(fullscreen: boolean): Void
- Enables or disables fullscreen
Development
Prerequisites
For building deno_webview the same prerequisites as for building deno is required (mostly).
Linux
- webkit2gtk (to install using apt:
sudo apt-get install libwebkit2gtk-4.0-dev
)
Cloning
To clone the repo simply run the following:
git clone https://github.com/eliassjogreen/deno_webview.git
and then cd into the repo:
cd deno_webview
Building
Building deno_webview takes about 20-50 minutes the first time (then like a minute) depending on your operating system. When building on Windows admin is required. Building is easiest done by running:
deno -A scripts/build.ts
or
cargo build --release --locked
optionally with mshtml
deno -A scripts/build.ts mshtml
or
cargo build --release --locked --no-default-features
Running
To run deno_webview without automatically downloading the binaries from
releases you will need
to use the enviornment variable DEV
and set it to the path where the binaries
are located. This is usually file://./target/release
. The process of running a
using local binaries can be easier to do using the
dev script:
deno -A scripts/dev.ts example.ts
Environment variables
DEV
- When developing locallyDEV
should be set to the local release path, usuallyfile://./target/release
MSHTML
- Due to MSHTML (ie) no longer being enabled by default the only way to enable it is to set theMSHTML
variable to the path of a binary build built with the--no-default-features
flag or usingdeno -A scripts/build.ts mshtml
Contributing
Contributions either in the form of pull requests or issues are always welcome.
Just remember to format using deno -A scripts/fmt.ts
(deno fmt
and
cargo fmt
). Thx <3
Dependencies
Deno
Rust
Todo
- Implement all most webview instance methods
- Docs
- Multiple windows/instances? (Help, need to create a static HashMap of
*mut CWebView
) Used solution found here - Better errors and responses from rust land
- Update ci so building with Edge works #3
- Two-way deno bindings (to call deno from javascript)
- More examples
- Tests (unsure of how though)
- Wait for the rust bindings to
update to the latest webview api.
- Polyfill for new API?