Skip to content

TypeError: app.onIpcMessage is not a function #14

Closed
@etornam45

Description

@etornam45
C:\Users\Etornam\Documents\codes\konja\try.js:5
app.onIpcMessage((data) => {
    ^

TypeError: app.onIpcMessage is not a function
    at Object.<anonymous> (C:\Users\Etornam\Documents\codes\konja\try.js:5:5)
    at Module._compile (node:internal/modules/cjs/loader:1565:14)
    at Object..js (node:internal/modules/cjs/loader:1708:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49

Node.js v22.12.0
const { Application } = require('@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();
const webview = window.createWebview({
  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();```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions