Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Oct 9, 2024
1 parent 41d2df9 commit eef5239
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![https://github.com/webviewjs/webview/actions](https://github.com/webviewjs/webview/workflows/CI/badge.svg)

Robust cross-platform webview library for Node.js written in Rust.
Robust cross-platform webview library for Node.js written in Rust. It is a native binding to [tao](https://github.com/tauri-apps/tao) and [wry](https://github.com/tauri-apps/wry) allowing you to easily manage cross platform windowing and webview.

![preview](https://github.com/twlite/webview/raw/main/assets/preview.png)

Expand All @@ -27,11 +27,11 @@ npm install @webviewjs/webview
| armv7-linux-androideabi ||
| aarch64-pc-windows-msvc ||

# Usage
# Examples

In this example, we will create a simple webview application that loads the Node.js website.
## Load external url

```javascript
```js
import { Application } from '@webviewjs/webview';
// or
const { Application } = require('@webviewjs/webview');
Expand All @@ -44,7 +44,45 @@ window.loadUrl('https://nodejs.org');
app.run();
```

# Examples
## IPC

```js
import { Application } from '@webviewjs/webview';

const app = new Application();

app.onIpcMessage((data) => {
const reply = `You sent ${data.body.toString('utf-8')}`;
window.evaluateScript(`onIpcMessage("${reply}")`);
});

const window = app.createBrowserWindow({
html: `<!DOCTYPE html>
<html>
<head>
<title>Webview</title>
</head>
<body>
<h1 id="output">Hello world!</h1>
<button id="btn">Click me!</button>
<script>
btn.onclick = function send() {
window.ipc.postMessage('Hello from webview');
}
</script>
</body>
</html>
`,
preload: `window.onIpcMessage = function(data) {
const output = document.getElementById('output');
output.innerText = \`Server Sent A Message: \${data}\`;
}`,
});

window.setTitle('WebviewJS + Node');

app.run();
```

Check out [examples](./examples) directory for more examples, such as serving contents from a web server to webview, etc.

Expand Down
2 changes: 2 additions & 0 deletions binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export interface BrowserWindowOptions {
backForwardNavigationGestures?: boolean
}
export interface HeaderData {
/** The key of the header. */
key: string
/** The value of the header. */
value?: string
}
export interface IpcMessage {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"noEmit": true
},
"include": ["."],
"exclude": ["node_modules", "bench", "__test__"]
Expand Down

0 comments on commit eef5239

Please sign in to comment.