diff --git a/README.md b/README.md index d0b8724..2fa23e8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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'); @@ -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: ` + + + Webview + + +

Hello world!

+ + + + + `, + 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. diff --git a/binding.d.ts b/binding.d.ts index a914303..0b89230 100644 --- a/binding.d.ts +++ b/binding.d.ts @@ -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 { diff --git a/tsconfig.json b/tsconfig.json index 5056788..554cc83 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "esModuleInterop": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "noEmit": true }, "include": ["."], "exclude": ["node_modules", "bench", "__test__"]