octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.3k stars 949 forks source link

Making robotjs context-aware #640

Closed Maltroth closed 1 year ago

Maltroth commented 3 years ago

Issue

This is an attempt to fix #580 and make robotjs context-aware and usable in the latest versions of Electron:

[1] (node:82611) Electron: Loading non-context-aware native module in renderer: '[...]/electron-app/node_modules/robotjs/build/Release/robotjs.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.

Reproduceble just by requiring robotjs anywhere in an Electron >= 9.0.0 app.

Electron and native apps

This means robotjs will simply stop working on Electron in the future.

Source: https://github.com/electron/electron/issues/18397

Changes

Context-awareness was added to node since version 10, to keep robotjs backward-compatible, I've put the new initialization in a version condition.

Tests

I tested on an Electron 9.4.0 app: it got rid of the error and I was able to use robotjs.


_Disclaimer: I'm not a C or C++ developer at all, I would need review so I'm not introducing something unwanted. Based myself on https://nodejs.org/api/addons.html#addons_context_aware_addons._

Maltroth commented 3 years ago

Seems to have outdated dependencies, there are a lot of errors or deprecated warnings on TravisCi for node.h and v8.h. Fail only on latest stable node 15.5.1 on linux.

Seems the case on all recent pull requests.