Skip to content

Commit bb55ded

Browse files
authored
docs: fix example
1 parent c82aa44 commit bb55ded

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,11 @@ app.run();
4848
## IPC
4949

5050
```js
51-
import { Application } from '@webviewjs/webview';
52-
5351
const app = new Application();
54-
55-
app.onIpcMessage((data) => {
56-
const reply = `You sent ${data.body.toString('utf-8')}`;
57-
window.evaluateScript(`onIpcMessage("${reply}")`);
58-
});
59-
6052
const window = app.createBrowserWindow();
53+
6154
const webview = window.createWebview({
62-
html: `<!DOCTYPE html>
55+
html: `<!DOCTYPE html>
6356
<html>
6457
<head>
6558
<title>Webview</title>
@@ -75,13 +68,18 @@ const webview = window.createWebview({
7568
</body>
7669
</html>
7770
`,
78-
preload: `window.onIpcMessage = function(data) {
71+
preload: `window.onIpcMessage = function(data) {
7972
const output = document.getElementById('output');
8073
output.innerText = \`Server Sent A Message: \${data}\`;
81-
}`,
74+
}`
8275
});
8376

84-
window.setTitle('WebviewJS + Node');
77+
if (!webview.isDevtoolsOpen()) webview.openDevtools();
78+
79+
webview.onIpcMessage((data) => {
80+
const reply = `You sent ${data.body.toString('utf-8')}`;
81+
window.evaluateScript(`onIpcMessage("${reply}")`)
82+
})
8583

8684
app.run();
8785
```

0 commit comments

Comments
 (0)