GithubHelp home page GithubHelp logo

winterreisender / webview-nodejs Goto Github PK

View Code? Open in Web Editor NEW
81.0 81.0 10.0 1.76 MB

A Node.js binding to webview

License: Apache License 2.0

JavaScript 8.00% CMake 0.76% C++ 90.66% SWIG 0.58%
cross-platform desktop javascript nodejs typescript webui webview

webview-nodejs's Introduction

webview-nodejs's People

Contributors

averynortonsmith avatar dirkk0 avatar fossabot avatar winterreisender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

webview-nodejs's Issues

Add to readme: how to install CMake on Windows.

When installing v0.4.0 on Windows 10, I got the error 'OMG CMake is not installed. Install CMake.'

I was able to solve this by running winget install Kitware.CMake. I also had to close and re-open my console to get the path to update.

Just putting this here in case anyone else gets stuck. Would be good to add this info to the readme.

Some examples stopped working (for me)

Hi,

I revisited this project and realized that something is not working for me in the latest version 0.2.4.
When I start a new project with npm install webview-nodejs not everything seems to be installed.

Downgrading to 0.1.3 makes the examples work again. According to my tests, just the trivial hello world example works, the more sophisticated ones (which use bind like this one at the bottom) do not work for me.

I am on node 19.9.

Thanks,
Dirk

Consider using Node-API

Currently we are using ffi-napi as our way to call C++ code from Node.js, It has pros and cons:

Pros:

  • Clean and tidy code base
  • Easy to use

Cons:

  • Not maintained activately
  • A little large in size
  • License issue in FOSSA

We may consider using Node-API(NAPI), the official way to call C++ code.

Pros:

  • Official
  • Smaller size
  • Can use swig interface from webview

Cons:

  • Difficult to build (has cmake.js and gyp, but we're using xmake)
  • Difficult to distribute

Make a decision:

  • Migrate to NAPI
  • Not now

Install failed on Big Sur

This command failed: sh -c node-gyp-build when trying to build (arch === arm64). I did a prior successful npm i node-gyp. Any hints?

Some Known Issues

Bugs

Need imporvement

  • Avoid extracting dll.
  • FOSSA License scanning(moved)

I'll try to follow what webview_deno do.

Node.js setInterval won't work

Discussed in #7

Originally posted by faveoled January 26, 2023
I noticed that setInterval routine stops working after I call show() on a webview. It there a way to go around that?

terminate window cause node to stop

hello guys,

in my code, I need to open a window, do some processing then terminate it then continue doing some processing.
but once I terminate the window the whole node code stop suddenly without any error, nothing is getting executed after window termination.

Deprecation notice libwebview-nodejs/src/webview.h

During build, there is a deprecation notice about the function call webkit_web_view_run_javascript() in webview.h:689.

The warning says: warning: 'void webkit_web_view_run_javascript(WebKitWebView*, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)' is deprecated: Use 'webkit_web_view_evaluate_javascript' instead [-Wdeprecated-declarations]

As of now, this warning doesn't cause any issues, but it may be worth being aware of.

Environment: Debian 12 with libwebkit2gtk-4.0-dev

navigator.mediaDevices suddenly undefined on Mac

I have been using webview-nodejs @0.1.5 on a Mac (Ventura) for a WebRTC app. Suddenly, (today) it stopped working because navigator.mediaDevices is now undefined. The same app works in a browser. I did not touch the webview-nodejs node modules. Is it possible that webview-nodejs is now denied user media access? I looked in system settings/privacy and security/camera and I don't see a webview entry but I never had to add it here before. As an aside, I cannot add apps to access the camera.

I've shutdown and restarted, to no avail. Any suggestions on how to troubleshoot this are appreciated.

Consider using Koffi

Koffi seems to be a new choice for FFI.
It's quite new and seems well tested.
It seems the right FFI we're looking for. I really hope I could meet this project earlier
Futher action including investigation, learning how to use it, rewriting the code and testing need to be done.

minimal text editor

Hi,

here's a minimal text editor:

https://gist.github.com/dirkk0/583c9633ea817f6a028939c4dc6dd729

Cheers, Dirk

Here's the one-fileversion:
---snip---

'use strict';

const { Webview } = require('webview-nodejs');
const fs = require("fs");

let w = null

let txt = "";
let path = "texteditor.txt";

let html = `
<html>

<style>
    #text {
        width: 100%;
        height: 90%;
    }
</style>

<body>
    <button onclick="doCmd('load')">load</button>
    <button onclick="doCmd('save', getText());">save</button>
    <button onclick="doCmd('quit');">quit </button>

    <div id="text" contenteditable>type something here ...</div>
</body>
<script>
    'use strict';

    function setText(t) {
        document.querySelector("#text").innerText = t
    }

    function getText() {
        return document.querySelector("#text").innerText
    }

    doCmd("load")

</script>

</html>
`


function main() {
    // let html = fs.readFileSync("texteditor.html", { encoding: "utf8", flag: "r" });

    w = new Webview(true);
    w.title("Minimal Text Editor");
    w.size(600, 400, 3);
    w.html(html);

    w.bind("doCmd", (w, c, t) => {
        console.log("cmd:", c);
        if (c == "quit") w.terminate();
        if (c == "load") {
            txt = fs.readFileSync(path, { encoding: "utf8", flag: "r" });
            txt = JSON.stringify(txt)
            w.eval(`setText(${txt})`);
        }
        if (c == "save") fs.writeFileSync(path, t, { encoding: "utf8" });

    });
    w.show();
};

main()

example with keybinding and log

Hi,

thanks for the nodejs bindings, much appreciated!

Because it wasn't completely obvious for me I created an example with keybindings (which are platform specific, this is for a Mac) and logging.

Maybe this is helpful for someone.

const { Webview } = require("webview-nodejs");

html = `
<body>
  <div id="d1"></div>
  <script>
    let counter = 0
    window.addEventListener("keypress", (event) => {
      if (event.metaKey && event.key === 'q') {
        doCmd("quit")
        event.preventDefault();
      }
    })

    setInterval(function () {
      document.querySelector("#d1").innerText = counter
      doLog("counter is " + counter)
      counter += 1
    }, 1000);
  </script>
</body>
`

let w = new Webview(true);

w.size(600, 600);
w.html(html);

w.bind("doLog", (w, t) => {
  console.log(t);
  w.title(t)
});

w.bind("doCmd", (w, cmd) => {
  console.log("cmd:", cmd);
  if (cmd == "quit") w.terminate();
});

w.show();

Remove TypeScript

Personally, I don't like TypeScript, so I decide to remove it later. A .d.ts file will still exist for users.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.