Run Selenium JavaScript on Raspberry PI 4 - javascript

I'm currently trying to run Selenium using the JavaScript Library. I'm trying to switch from Python due to performance improvements with JavaScript (twice the speed in some cases).
However I'm having trouble since the NPM package chromdriver does not work on a Raspberry Pi since it has a OS requirement of Linux 64 bit.
I'm trying to link my chromedriver path to the driver builder but I'm getting errors.
JavaScript Code:
try {
const options = new Chrome.Options();
options.addArguments(['--headles=new'])
options.setChromeBinaryPath("/usr/local/bin/chromedriver")
//Chrome.setDefaultService(new
Chrome.ServiceBuilder("/usr/local/bin/chromedriver").build())
// Create a new Selenium webdriver
driver = await new Builder()
.setChromeOptions(options)
.setChromeService()
.forBrowser('chrome')
.build();
console.log(driver)
} catch (error) {
console.log(error)
await driver.quit();
return error
}
The error:
WebDriverError: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/local/bin/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
at Object.throwDecodedError (/Users/Documents/node_modules/selenium-webdriver/lib/error.js:524:15)
at parseHttpResponse (/Users/Documents/node_modules/selenium-webdriver/lib/http.js:587:13)
at Executor.execute (/Users/Documents/node_modules/selenium-webdriver/lib/http.js:515:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
remoteStacktrace: '0 chromedriver 0x000000010d60ff38 chromedriver + 4910904\n' +
'1 chromedriver 0x000000010d58fa03 chromedriver + 4385283\n' +
'2 chromedriver 0x000000010d1d4747 chromedriver + 472903\n' +
'3 chromedriver 0x000000010d201930 chromedriver + 657712\n' +
'4 chromedriver 0x000000010d1fd4a2 chromedriver + 640162\n' +
'5 chromedriver 0x000000010d248460 chromedriver + 947296\n' +
'6 chromedriver 0x000000010d247cbf chromedriver + 945343\n' +
'7 chromedriver 0x000000010d23eee3 chromedriver + 909027\n' +
'8 chromedriver 0x000000010d20930c chromedriver + 688908\n' +
'9 chromedriver 0x000000010d20a88e chromedriver + 694414\n' +
'10 chromedriver 0x000000010d5dd1de chromedriver + 4702686\n' +
'11 chromedriver 0x000000010d5e1b19 chromedriver + 4721433\n' +
'12 chromedriver 0x000000010d5e928e chromedriver + 4752014\n' +
'13 chromedriver 0x000000010d5e291a chromedriver + 4725018\n' +
'14 chromedriver 0x000000010d5b6b02 chromedriver + 4545282\n' +
'15 chromedriver 0x000000010d601888 chromedriver + 4851848\n' +
'16 chromedriver 0x000000010d601a05 chromedriver + 4852229\n' +
'17 chromedriver 0x000000010d617e5f chromedriver + 4943455\n' +
'18 libsystem_pthread.dylib 0x00007ff81918d259 _pthread_start + 125\n' +
'19 libsystem_pthread.dylib 0x00007ff819188c7b thread_start + 15\n'
}

Related

Passing a Jar arguments from Javascript in Ubuntu

I've got a Javascript snippet I am using successfully to pass arguments to a jar file for calculations on my windows machine but when I uploaded it to my server its telling me it cannot access the jar file. I can run the jar file from terminal on my Ubuntu server so I am not entire sure why it's not working from the JavaScript file.
const cmdArgs = [...vendFat, priceFat, amountFat];
/* variable 'command line code' */
const cmdCode = `java -jar ./Java2/createOrder.jar ${cmdArgs}`;
var exec = require('child_process').exec, child;
child = exec(cmdCode,
function (error, stdout, stderr){
console.log('Response: ' + JSON.stringify(stdout));
res.send(stdout);
//console.log('stderr: ' + stderr);
if(error !== null){
console.log('exec error: ' + error);
}
});
And here is the terminal response:
exec error: Error: Command failed: java -jar ./Java2/createOrder.jar s,e,l,l,0,100
Error: Unable to access jarfile ./Java2/createOrder.jar

How to make this javascript code run on Windows 8.1?

This is a piece of code used to import subscriptions from one Youtube account to another by opening up a new Google Chrome tab/window with a channel url from the list inside the downloaded subscription_manager.xml file. When I use node to open the "app.js" file it shows no errors but it never opens Chrome. I think because the creator of the code was using Mac Os, he may have written something that isn't compatible in Windows. Can someone verify this to make sure it works for Windows too? Link to video "https://youtu.be/GVakGPDF3Kc"
var fs = require('fs'),
childProcess = require('child_process'),
xml2js = require('xml2js');
var parser = new xml2js.Parser();
fs.readFile(__dirname + '/subscription_manager.xml', function (err, data) {
parser.parseString(data, function (err, result) {
var nodes = result.opml.body[0].outline[0].outline;
nodes.forEach(function (node, index) {
var url = node['$'].xmlUrl;
url = url.substring(url.indexOf('=') + 1, url.length);
var channel = 'https://www.youtube.com/channel/' + url;
if (index == 1) {
childProcess.exec('open -a "Google Chrome" ' + channel);
}
});
});
});
You're right about the MacOS vs Windows portion - this code:
childProcess.exec('open -a "Google Chrome" ' + channel);
is for the MacOS terminal. You could try changing it to:
childProcess.exec('start chrome ' + channel);
(Tested on Windows 10)

I'm getting a net::ERR_INSECURE_RESPONSE with socket.io/node.js

Here is the current code that I am using to try to connect my web application running socket.io to my node application.
var options = {
key: fs.readFileSync('csgo2x.key').toString(),
cert: fs.readFileSync('csgo2x.crt').toString(),
ca : [fs.readFileSync("csgo2x.pem").toString()],
rejectUnauthorized: false
};
var server = require('https').createServer(options);
var portNo = 443;
server.listen(portNo, function() {
console.log((new Date()) + " Server is listening on port " + portNo);
});
However...when I try to connect my socket.io application running on my Ubuntu server...it gives the error net::ERR_INSECURE_RESPONSE.
I am using certificates from Cloudflare btw and for some reason it's not working

CoffeeScript Reference error

So I keep getting the following error with my code:
Reference Error: ws is not defined
My code is this:
config = require "./config.json"
chalk = require "chalk"
shortid = require "shortid"
maxplayers = config.maxplayers
WebSocketServer = require("ws").Server
wss = new WebSocketServer({port: config.port})
wss.on "connection", (ws) ->
console.log "Socket " + chalk.green("connected") + "."
ws.on "message", (msg) ->
console.log "Received packet: " + msg
return
console.log "Server " + chalk.cyan("started") + " on port " + config.port + "."
Why is this happening? CoffeeScript's Try page gives me exactly what I want. Why does NPM CoffeeScript not do it? If I do coffee -c myscriptname (yes I replaced myscriptname with my script name), it gives me this:
// Generated by CoffeeScript 1.9.1
(function() {
ws.on("message", function(msg) {
return console.log("Received packet: " + msg);
});
return;
}).call(this);

registration using sip.js and websockets in Node (wss or ws)

I'm trying to register SIP agents using sip.js and Node to start load testing to my Kamailio
Node version v0.10.32
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
global.WebSocket = require('ws')
// SipJS Initialization
var SIP = require('./sip-0.6.0.js');
var Uaconfig = {
traceSip: true,
register: true,
userAgentString: 'sipJS Test tool',
uri: 'ramenlabs.io',
wsServers: ['wss://ramenlabs.io:5063'],
authorizationUser: 'gogasca',
password: '********'
//hackIpInContact: true
};
var userAgent = new SIP.UA(Uaconfig);
When I run I get an error:
Thu Oct 16 2014 03:40:53 GMT+0000 (UTC) | sip.transport | WebSocket connection error: Error: unexpected server response (400)
Because initial Websocket from Sip.js lacks Sec-WebSocket-Protocol: sip to indicate SIP Protocol.
If i use sample web page it works perfectly with same parameters, but not from my node command line.
How to force this?
In API js I do see the 'sip' extra header but contains the window.Websocket
try {
this.ws = new window.WebSocket(this.server.ws_uri, 'sip');
}
catch(e) {
this.logger.log('Error connecting to WebSocket ' + this.server.ws_uri + ': ' + e);
//return false;
}
You can set debug=3 in kamailio.cfg, restart and try again. Then look in syslog file (/var/log/syslog or /var/log/messages) for debug messages from Kamailio to see if you get a hint on why the connection is not accepted.

Categories

Resources