Node.js Library Cannot Enter Keyboard

Asked 2 years ago, Updated 2 years ago, 105 views

I wanted to use the game pad to enter characters on MacOS, so I was creating a program.
My language and environment is javascript/node.js/Electron, and my library is robot.js.

The keyboard input emulation worked well in the early stages of production.However, when I ran the keyboard input method from one point on, the characters were not entered and the electron dropped.

Tested without Electron because no errors were displayed.If it works correctly, a code will be entered.

constrobot=require('robotjs');
robot.keyTap('a');

As a result, no characters were entered, and the following output appeared:

zsh:segmentation fault node

When I looked into this error, I was told that I could see the detailed log in the library called segfault-handler, so I put it in place as follows:

const SegfaultHandler=require('segfault-handler');
SegfaultHandler.registerHandler('crash.log');
constrobot=require('robotjs');
robot.keyTap('a');

The log output returned was as follows.
I couldn't read the details of this output.

 PID 2643 received SIGSEGV for address:0x0
0segfault-handler.node 0x0000000106ea534c_ZL16segfault_handleriP9__siginfoPv+288
1libsystem_platform.dylib0x00000001b853d4c4_sigtramp+56
2 robotjs.node0x0000000106ed66d0keyCodeForChar+276
3 robotjs.node0x0000000106ed2b6c_Z6keyTapRKN3 Nan 20 FunctionCallbackInfoIN2v85ValueEE+300
4 robotjs.node0x0000000106ed5818_ZN3Nan3impL23 FunctionCallbackWrapperERKN2v820 FunctionCallbackInfoINS1_5ValueEE+208
5node 0x00000001027c4adc_ZN2v88 internal 25 FunctionCallbackArguments 4CallENS0_15CallHandlerInfoE+540
6node0x00000001027c4090_ZN2v88 internal12_GLOBAL_N_119 HandleApiCallHelperILb0EENS0_11 MaybeHandleINS0_6ObjectEEEPNS0_7 IsolateENS0_6 HandleINS0_10HeapObjectEEESA_NS8_INS0_20 FunctionTemplateInfoil_ENS0_8ENS0_ENS0_20ENS0_20ENS0_20ENS0_20ENS0_ENS0_20
7node 0x00000001027c3894_ZN2v88 internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE+228
8node 0x0000000102f4bf8cBuiltins_Centry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit+108
9node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
10node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
11 node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
12 node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
13 node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
14 node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
15 node 0x0000000102ee6478Builtins_InterpreterEntryTrampoline+248
16 node 0x0000000102ee42ac Builtins_JSEntryTrampoline+172
17node 0x0000000102ee3f44Builtins_JSEntry+164
18 node 0x000000010288 dcdc_ZN2v88 internal12_GLOBAL_N_16 InvokeEPNS0_7 IsolateERKNS1_12 InvokeParamsE+2536
19 node 0x000000010288d2dc_ZN2v88 internal 9 Execution 4 CallEPNS0_7 IsolateENS0_6 HandleINS0_6 ObjectEEES6_iPS6_+200
20node 0x000000010275d6fc_ZN2v88 Function 4CallENS_5LocalINS_7ContextEENS1_INS_5ValueEEiPS5_+448
21node0x00000001025c54c8_ZN4node19ExecuteBootstrapperEPNS_11EnvironmentEPKcPNSt3__16vectorIN2v85LocalINS6_6 StringEENS4_9allocatorIS9_EEEPNS5_INS7_INS6_5 ValueEENSA_ISF_EEEE+100
22 node0x00000001025c64a4_ZN4nodeL14StartExecutionEPNS_11 EnvironmentEPKc+312
23node0x00000001025c6350_ZN4node14StartExecutionEPNS_11EnvironmentESt3__18 functionIFN2v810MaybeLocalINS4_5ValueEEERKNS_26StartExecutionCallbackInfoEEEE+1044
24node0x0000000102549970_ZN4node15LoadEnvironmentEPNS_11EnvironmentESt3__18 functionIFN2v810MaybeLocalINS4_5ValueEEERKNS_26StartExecutionCallbackInfoEE+136
25 node0x000000010262cb78_ZN4 node16 NodeMainInstance3RunEPiPNS_11 EnvironmentE+72
26node0x000000010262c888_ZN4node16NodeMainInstance3RunEPKNS_16EnvSerializeInfoE+120
27 node 0x00000001025c847c_ZN4node5StartEiPPc+180
28 dyld0x0000000107089088 start +516

Just like robot.js, we tested the same thing with nut.js, which can operate the keyboard and mouse.This one used to work too.

const {keyboard}=require('@nut-tree/nut-js');
keyboard.type(45);

The results were the same.

zsh:segmentation fault node

Same code and log output for deploying segfault-handler

const SegfaultHandler=require('segfault-handler');
SegfaultHandler.registerHandler('crash.log');
const {keyboard} = require('@nut-tree/nut-js');
keyboard.type(45);

PID11392 received SIGSEGV for address:0x0
0segfault-handler.node 0x000000010719134c_ZL16segfault_handleriP9__siginfoPv+288
1 libsystem_platform.dylib 0x00000001922894c4_sigtramp+56
2 libnut.node0x00000001071f4054keyCodeForChar+276
3libnut.node0x00000001071efa0c_Z7_keyTapRKN4Napi12 CallbackInfoE+188
4libnut.node0x00000001071f3858_ZN4Napi7details12WrapCallbackIZNS0_12CallbackDataIPFNS_6 NumberERKNS_12CallbackInfoEES3_E7WrapperEP10napi_env_P20napi_callback_info_EUlvE_EEP12napi_value+
5libnut.node0x00000001071f3800_ZN4Napi7details12CallbackDataIPFNS_6NumberERKNS_12CallbackInfoEES2_E7WrapperEP10napi_env_P20napi_callback_info_+28
6node 0x00000001028a03b0_ZN6v8impl12_GLOBAL__N_123 FunctionCallbackWrapper6 InvokeERKN2v820 FunctionCallbackInfoINS2_5ValueEE+104
7node 0x0000000102aa8adc_ZN2v88 internal 25 FunctionCallbackArguments 4CallENS0_15CallHandlerInfoE+540
8node 0x0000000102aa8090_ZN2v88 internal12_GLOBAL_N_119 HandleApiCallHelperILb0 EENS0_11 MaybeHandleINS0_6 ObjectEEEPNS0_7 IsolateENS0_6 HandleINS0_10HeapObjectEEESA_NS8_INS0_20 FunctionTemplateInfil_ENS0_8_ENS0_20ENS0_ENS0_20ENS0_20ENS0_ENS0_20
9node 0x0000000102aa7894_ZN2v88 internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE+228
10node 0x000000010322ff8cBuiltins_Centry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit+108
11 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
12 node 0x00000001032742c0Builtins_PromiseConstructor +2208
13 node 0x00000001031c76f0Builtins_JSBuiltinsConstructStub+368
14 node 0x00000001032b87dc Builtins_ConstructHandler +636
15 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
16 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
17node 0x00000001032742c0Builtins_PromiseConstructor+2208
18 node 0x00000001031c76f0Builtins_JSBuiltinsConstructStub+368
19node 0x00000001032b87dcBuiltins_ConstructHandler+636
20node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
21 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
22 node 0x00000001031ca478 Builtins_InterpreterEntryTrampoline +248
23 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
24node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
25 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
26node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
27 node 0x00000001031ca478Builtins_InterpreterEntryTrampoline+248
28 node 0x00000001031c82ac Builtins_JSEntryTrampoline+172
29 node 0x00000001031c7f44Builtins_JSEntry+164
30 node 0x0000000102b71 cdc_ZN2v88 internal12_GLOBAL_N_16 InvokeEPNS0_7 IsolateERKNS1_12 InvokeParamsE+2536
31 node 0x0000000102b712dc_ZN2v88 internal 9 Execution 4 CallEPNS0_7 IsolateENS0_6 HandleINS0_6 ObjectEEES6_iPS6_+200

There are similar errors in different libraries, so I expect access rights or something to be involved, but I can't think of any more concrete ways to dig into them.
It was originally a working cord, so there is no cause for pinning.I would appreciate it if you could let me know something.

MacOS Monterey 12.3
node v16.4.1
electron v13.1.5
robot.js 0.6.0
nut.js 2.0.1

Add

I created a different account in Mac than the one I usually use for development, and when I ran the code above, it worked.
Should I see this as some kind of software interfering with keystrokes on my regular account?

Additional 2 (2022.6.26)

For the code above, see

$sudonode 

I ran it with the command and it worked.

What kind of situation can you think of in terms of code and environment if it is not sudo or segmentation fault will occur?
I finally used it with Electron, so I'd like to clarify that.

In response to akiraejiri's response, I looked into the system call trace and tried to do it.

 sudodtruss-f sudo-u$(id-u-n)node...

The output returned was as follows:

 dtrace:system integrity protection is on, some features will not be available

dtrace:failed to execute sudo:Operation not permitted

From this statement, I wondered if turning off System Integrity Protection (SIP) would work (from here on MacOS level), so I started macOS recovery and tried to change the security settings by referring to the following site:
https://www.too.com/support/faq/mac/maintenance/23554.html
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q13252085413
https://ascii.jp/elem/000/004/048/4048177/2/

Attempted Input and Output in Terminal

-bash-3.2#csrutil disable
csutil —The OS environment does not allow changing security configuration options.
Ensure that the system was booted into Recovery OS via the standard user action.

Warnings When Opening the Boot Security Utility

You cannot change the security settings.
To change your security settings, power off your Mac and hold down the power button to start macOS recovery.

In other words, both of them are running from the recovery menu, but they say, 'You can't change them until you boot from recovery.'

javascript macos node.js

2022-09-30 15:01

1 Answers

What kind of code and environmental situation can you think of if it's not sudo or segmentation fault occurs?

If there are actions that fail without root privileges (e.g., system call calls) and error checking is negligible, it is not surprising that subsequent actions result in a "segmentation fault."

Tracing a system call may help you understand the cause.

 sudodtruss-f sudo-u$(id-u-n)node

The error does not appear to be reproduced if you run it as root user, so you may want to compare it with the result when you run it as root.

 sudo dtruss-f node


2022-09-30 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.