File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,18 +48,11 @@ app.run();
4848## IPC
4949
5050``` js
51- import { Application } from ' @webviewjs/webview' ;
52-
5351const 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-
6052const window = app .createBrowserWindow ();
53+
6154const 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
8684app .run ();
8785```
You can’t perform that action at this time.
0 commit comments