本机javascript加载项无法使其在浏览器上运行
我是javascript新手,我正在尝试使用本机插件,并在控制台下使用node对其进行编译和测试。然而,当它包含在html中并在chrome下运行时,它总是说require没有定义。然后我使用browserify将其捆绑,但我收到了以下消息: 分析错误:意外字符“?” index.js:本机javascript加载项无法使其在浏览器上运行,javascript,node.js,browserify,Javascript,Node.js,Browserify,我是javascript新手,我正在尝试使用本机插件,并在控制台下使用node对其进行编译和测试。然而,当它包含在html中并在chrome下运行时,它总是说require没有定义。然后我使用browserify将其捆绑,但我收到了以下消息: 分析错误:意外字符“?” index.js: const Input = require('./build/release/sendinput.node'); console.log('test',Input); function SendInput(in
const Input = require('./build/release/sendinput.node');
console.log('test',Input);
function SendInput(inputs){
if(!Array.isArray(inputs))
inputs = [inputs];
let arr = [];
for(let inp of inputs){
if(typeof inp != "object")
throw new Error("Expecting array of objects");
if(!Number.isInteger(inp.type) || inp.type < 0 || inp.type > 2)
throw new Error("Expecting type to be an integer from 0 to 2");
if(!Number.isInteger(inp.val))
throw new Error("Expecting val to be an integer")
switch(inp.type){
case 0:
arr.push(Input.CreateKBDInpVKey(inp.val, !!inp.up));
break;
case 1:
let val = inp.val;
let extended = false;
if(val >> 8 & 0xFF == 0xe0)
extended = true;
arr.push(Input.CreateKBDInpScanCode(inp.val & 0xFF, !!inp.up, extended));
break;
case 2:
arr.push(Input.CreateKBDInpUnicode(inp.val, !!inp.up));
break;
}
}
return Input.SendInput(arr);
}
module.exports = {SendInput} //SendInput now a object.
我需要让他们在浏览器上工作。有人能帮我吗?谢谢您不能在浏览器上使用本机节点模块,仅此而已。
您可以运行Nodejs rest服务器,使用从浏览器到服务器的rest调用,让Nodejs完成工作并在浏览器上使用响应,就是这样。谢谢,在我做了一些研究之后,我明白了您的意思。我看到有人推荐编译EnScript来编译C++本地人到JavaScript然后再运行Runon Web浏览器,这有意义吗?感谢该模块作为“节点本机模块”工作,它可能使用了N-API、v8和其他东西,要将其编译为“web程序集”,您需要重写该模块,然后进行编译。
test {
SendInput: [Function],
CreateKBDInpVKey: [Function],
CreateKBDInpScanCode: [Function],
CreateKBDInpUnicode: [Function]
}