guest271314 / native-messaging-nodejs

Node.js Native Messaging host
Do What The F*ck You Want To Public License
15 stars 0 forks source link

Native host has exited. #2

Closed Sneaken closed 2 months ago

Sneaken commented 2 months ago

use your nm_nodejs.js

chrome.runtime.lastError is 'Native host has exited'.

i don't know what happened.. can you help me?

env: m1 mac node 20 chrome: 126.0.6478.127 arm64

image image image

guest271314 commented 2 months ago

Is nm_node.js is set executable?

Sneaken commented 2 months ago

Is nm_node.js is set executable?

yes

chmod +x ./nm_nodejs.js

guest271314 commented 2 months ago

Make sure the value of "path" in nm_nodejs.json is pointing to the absolute path to the file on the file system. Also try with each of the following flags on shebag line removed --max-old-space-size=14 --jitless --expose-gc --v8-pool-size=1.

guest271314 commented 2 months ago

Excluding --expose-gc, which doesn't change anything with regard to node exiting, while the others can.

guest271314 commented 2 months ago

Did you update the shebang line in nm_nodejs.js to point to the absolute path to the node executable you are using?

#!/usr/bin/env -S /home/user/bin/node  --expose-gc  --experimental-default-type=module
Sneaken commented 2 months ago

Did you update the shebang line in nm_nodejs.js to point to the absolute path to the node executable you are using?

#!/usr/bin/env -S /home/user/bin/node  --expose-gc  --experimental-default-type=module

yes , but no change

#!/usr/bin/env -S /Users/sneaken/.volta/bin/node --expose-gc --experimental-default-type=module
guest271314 commented 2 months ago

The only other report I have gotten was from another Mac user. I'm running the same code you are running on Linux, Chromium 128.

Screenshot_2024-07-15_00-35-23

What happens when you try Deno, Bun, and shell script as Native Messaging hosts?

Sneaken commented 2 months ago

I tried the official Python code, and it works. This is strange because only Node.js doesn’t work on my computer.

guest271314 commented 2 months ago

Here are a few Native Messaging hosts that should all send back the same result, an Array with length 209715, 1048576 bytes as JSON https://github.com/guest271314/NativeMessagingHosts.

It's probably something like paths not being absolute or files not being executable.

I would reload the extension. Go over the code until you locate the issue. Is node executable?

guest271314 commented 2 months ago

This script should work using node, deno, or bun https://github.com/guest271314/NativeMessagingHosts/blob/main/nm_host.js. What happens when you substitute adjust "path" in nm_nodejs.json to nm_host.js, adjust shebang line, make the script executable and run the code?

Sneaken commented 2 months ago

Here are a few Native Messaging hosts that should all send back the same result, an Array with length 209715, 1048576 bytes as JSON https://github.com/guest271314/NativeMessagingHosts.

It's probably something like paths not being absolute or files not being executable.

I would reload the extension. Go over the code until you locate the issue. Is node executable?

Error when communicating with the native messaging host.

image image

Sneaken commented 2 months ago

Here are a few Native Messaging hosts that should all send back the same result, an Array with length 209715, 1048576 bytes as JSON https://github.com/guest271314/NativeMessagingHosts.

It's probably something like paths not being absolute or files not being executable.

I would reload the extension. Go over the code until you locate the issue. Is node executable?

python can run... my God

guest271314 commented 2 months ago

Sounds like a path or executable permission issue.

guest271314 commented 2 months ago

In the last image you posted you are pointing to node on the shebang. In the other image you pointed to /Users/sneaken/.volta/bin/node.

Make sure you are pointing to the absolute pathe to node if node is not installed system wide.

Sneaken commented 2 months ago

Sounds like a path or executable permission issue.

sorry, nm_host.js need node 21, when i install it, it can run!!

guest271314 commented 2 months ago

In theory nm_nodejs.js should run, too. I'm not sure if pointing to the file descriptors /dev/stdin and /proc/self/fd/1 is an issue on Mac.

Sneaken commented 2 months ago

Here are a few Native Messaging hosts that should all send back the same result, an Array with length 209715, 1048576 bytes as JSON https://github.com/guest271314/NativeMessagingHosts.

It's probably something like paths not being absolute or files not being executable.

I would reload the extension. Go over the code until you locate the issue. Is node executable?

but nm_nodejs.js still like that... MY GOD

Sneaken commented 2 months ago

In theory nm_nodejs.js should run, too. I'm not sure if pointing to the file descriptors /dev/stdin and /proc/self/fd/1 is an issue on Mac.

I feel like this might be the problem

Sneaken commented 2 months ago

Although I don’t know what happened, thank you for answering my questions. :)

guest271314 commented 2 months ago

I don't generally use Apple devices. Thanks for the feedback re Mac and nm_nodejs.js.

nm_node.js.js works for me on Linux, with node and Chromium from tip-of-tree releases fetched today.

I wrote nm_host.js as a JavaScript runtime agnostic approach to reading standard input and writing to standard output, primarily using WHATWG Streams that is not part of ECMA-262 though works reliably for streaming Uint8Arrays and resizable ArrayBuffer, with dataView to read "32-bit message length in native byte order.". Unfortunately, reading standard input and writing to standard output is not standardized in ECMA-262, so it's continual W.I.P. to use the same code across engines and runtimes, e.g., Bun.stdin.stream() does not beahve the same as Bun.file("/dev/stdin").stream().

What happens when you try this code https://github.com/simov/native-messaging/blob/8e99d2a345ae94426a502d05aa5d57b966f6bc78/protocol.js and this code https://github.com/guest271314/NativeMessagingHosts/blob/5306ae8a09f6dd1e8053e737ad244ffd7ca2ecb3/nm_nodejs.mjs?

guest271314 commented 2 months ago

Although I don’t know what happened, thank you for answering my questions. :)

No worries.

Sneaken commented 2 months ago

use https://github.com/guest271314/NativeMessagingHosts/blob/5306ae8a09f6dd1e8053e737ad244ffd7ca2ecb3/nm_nodejs.mjs

emmm... haha

image

guest271314 commented 2 months ago

Did you remove --max-old-space-size=6, --jitless, and --v8-pool-size=1 flags from shebang line?

And if that doesn't change anything, removing process.env.UV_THREADPOOL_SIZE = 1; and process.stdout._handle.setBlocking(true);?

Sneaken commented 2 months ago

this can work https://github.com/simov/native-messaging/blob/8e99d2a345ae94426a502d05aa5d57b966f6bc78/protocol.js

Sneaken commented 2 months ago

Did you remove --max-old-space-size=6, --jitless, and --v8-pool-size=1 flags from shebang line?

And if that doesn't change anything, removing process.env.UV_THREADPOOL_SIZE = 1; and process.stdout._handle.setBlocking(true);?

this all no change, maybe should use stream on mac

Sneaken commented 2 months ago

Thank you once again 😆