Selenium on heroku DevToolsActivePort file doesn't exist - node.js

So, I'm trying to deploy a node, selenium app to heroku.
This is how my code looks
let options = new Options();
options.setChromeBinaryPath(process.env.GOOGLE_CHROME_BIN);
options.addArguments("--headless");
options.addArguments("--start-maximized");
options.addArguments("--headless");
options.addArguments("--disable-dev-usage");
options.addArguments("--window-size=1920,1080");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
options.setUserPreferences({"prefs":{"useAutomationExtension": false}});
let serviceBuilder = new ServiceBuilder();
console.log("initialized serice builder");
let driver = new Builder(process.env.CHROME_EXECUTABLE_PATH)
.forBrowser(Browser.CHROME)
.setChromeOptions(options)
.setChromeService(serviceBuilder)
.build();
This throws an error on the heroku logs like so
2021-05-18T05:42:15.372134+00:00 app[web.1]: /app/node_modules/selenium-webdriver/lib/error.js:517
2021-05-18T05:42:15.372174+00:00 app[web.1]: let err = new ctor(data.message)
2021-05-18T05:42:15.372175+00:00 app[web.1]: ^
2021-05-18T05:42:15.372176+00:00 app[web.1]:
2021-05-18T05:42:15.372176+00:00 app[web.1]: WebDriverError: unknown error: Chrome failed to start: crashed.
2021-05-18T05:42:15.372177+00:00 app[web.1]: (unknown error: DevToolsActivePort file doesn't exist)
2021-05-18T05:42:15.372180+00:00 app[web.1]: (The process started from chrome location /app/.apt/opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:517:15)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:642:13)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:568:28)
2021-05-18T05:42:15.372182+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2021-05-18T05:42:15.372182+00:00 app[web.1]: remoteStacktrace: '#0 0x5630d5f6be89 <unknown>\n'
2021-05-18T05:42:15.372183+00:00 app[web.1]: }
2021-05-18T05:42:15.465529+00:00 heroku[web.1]: Process exited with status 1
2021-05-18T05:42:15.532468+00:00 heroku[web.1]: State changed from up to crashed
Nothing seems to fix the issue, I've added the required buildpacks, and have also checked all the versions. Also note that this code runs perfectly fine on my local machine. I saw a similar question where the user manually added the DevToolsActivePort file, but that doesn't seem to be possible as I can't ssh into the heroku server.
Thanks in advance.

You will need to pass in a flag to disable Chrome Devtools Sandbox, so it will no longer look for DevToolsActivePort. It is also recommended to disable-gpu with a headless webdriver:
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-gpu");

Related

Nanoexpress server fails on Heroku & AWS - runs fine locally - cannot trace 'dest.on()' error

Relevant stack-trace below - from Heroku:
2020-04-28T17:49:11.997756+00:00 app[web.1]: Your app is listening on port 14385
2020-04-28T17:49:12.491486+00:00 heroku[web.1]: State changed from starting to up
2020-04-28T17:49:41.748150+00:00 heroku[web.1]: State changed from up to crashed
2020-04-28T17:49:41.649885+00:00 app[web.1]: _stream_readable.js:660
2020-04-28T17:49:41.649896+00:00 app[web.1]: dest.on('unpipe', onunpipe);
2020-04-28T17:49:41.649897+00:00 app[web.1]: ^
2020-04-28T17:49:41.649897+00:00 app[web.1]:
2020-04-28T17:49:41.649898+00:00 app[web.1]: TypeError: dest.on is not a function
2020-04-28T17:49:41.649899+00:00 app[web.1]: at ReadStream.Readable.pipe (_stream_readable.js:660:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.stream (/app/node_modules/send/index.js:798:10)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.send (/app/node_modules/send/index.js:707:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at /app/node_modules/send/index.js:774:12
2020-04-28T17:49:41.649901+00:00 app[web.1]: at FSReqCallback.oncomplete (fs.js:172:5)
From AWS (EC2 using a Bitnami instance for NodeJS apps):
Your app is listening on port 8080
_stream_readable.js:666
dest.on('unpipe', onunpipe);
^
TypeError: dest.on is not a function
at ReadStream.Readable.pipe (_stream_readable.js:666:8)
at SendStream.stream (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:798:10)
at SendStream.send (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:707:8)
at /opt/bitnami/apps/coronavirus-demo/htdocs/node_modules/send/index.js:774:12
at FSReqCallback.oncomplete (fs.js:167:5)
error: Forever detected script exited with code: 1
error: Script restart attempt #1
I see that we seem to be dying on _stream_readable.js:666 where 'dest.on' isn't defined - and I'm way into the weeds of Node at this point - so I'm not sure what I'm looking for, but I find that we're defining this method further down in the file:
https://github.com/nodejs/node/blob/master/lib/_stream_readable.js:852 -
Is this as simple as we're evaluating this _stream_readable file top-down and we haven't defined on() as of line 666 and that's why it's failing?
But why would it work locally? The app runs fine with Nanoexpress server on a Macbook Pro - same package.json and lock files - no devDependencies that make any difference (the only devDependencies are like Mocha and Sinon and Chai for tests)
I've run the app locally with NODE_ENV=production and NPM_CONFIG_PRODUCTION=true (it's a React & Express [Nanoexpress] app) and it boots and I can get what I need running just fine.
It's only when I push to Heroku / AWS that I'm getting this failure. Feels like we're trying to use a function before it's defined...
nanoexpress author here.
nanoexpress works fine on Heroku on my projects, but on AWS did not test, but nanoexpress does not support Lambda/Serverless.
Please check first your code or try PRO version as now it's Free

METEOR_SETTINGS is not valid json error when deploying meteor app to heroku

As the title says, I am getting that error when deploying my meteor app to heroku. I have already validated my settings.json file with JSONlint and have searched for any possible fix but I have not come across any which work. My error logs are as shown below. Could anyone tell me what might be wrong?
2017-09-03T11:18:31.226632+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node $NODEJS_PARAMS .meteor/heroku_build/app/main.js`
2017-09-03T11:18:33.344368+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/boot.js:391
2017-09-03T11:18:33.344382+00:00 app[web.1]: }).run();
2017-09-03T11:18:33.344383+00:00 app[web.1]: ^
2017-09-03T11:18:33.344384+00:00 app[web.1]:
2017-09-03T11:18:33.344385+00:00 app[web.1]: Error: METEOR_SETTINGS are not valid JSON: $(cat settings.json)
2017-09-03T11:18:33.344385+00:00 app[web.1]: at packages/meteor.js:59:11
2017-09-03T11:18:33.344386+00:00 app[web.1]: at packages/meteor.js:80:4
2017-09-03T11:18:33.344387+00:00 app[web.1]: at packages/meteor.js:1380:3
2017-09-03T11:18:33.344388+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:338:34
2017-09-03T11:18:33.344388+00:00 app[web.1]: at Array.forEach (native)
2017-09-03T11:18:33.344389+00:00 app[web.1]: at Function._.each._.forEach (/app/.meteor/heroku_build/app/programs/server/node_modules/underscore/underscore.js:79:11)
2017-09-03T11:18:33.344390+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:158:5
2017-09-03T11:18:33.344391+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:387:5
2017-09-03T11:18:33.344392+00:00 app[web.1]: at Function.run (/app/.meteor/heroku_build/app/programs/server/profile.js:510:12)
2017-09-03T11:18:33.344392+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:386:11
2017-09-03T11:18:33.415049+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-03T11:18:33.400865+00:00 heroku[web.1]: Process exited with status 1
Your problem is with this command:
heroku config:add METEOR_SETTINGS="$(cat settings.json)"
You see, on Windows, the $(cat settings.json) means just text, but on Mac/*nix that means "get content of settings.json file".
I'd recommend to use git bash cli to run this command there. Link to Git for Windows (with git bash cli): https://git-for-windows.github.io/
In windows, you can compress the setting.json file in notepad++ (Plugins->JSON viewer -> Compress JSON) then run the below command by coping the compressed json content as follow
SET METEOR_SETTINGS={"configuration":{"images-folder":"","internal-folder":"","demo-mode":false},"sets-of-classes":[{"name":"Cityscapes","objects":[{"label":"VOID","color":"#CFCFCF"},{"label":"Road","color":"#804080","icon":"Road"},{"label":"Sidewalk","........
now you can run the usual command

Sequelize giving TypeError

So I was casually devoloping a simple node.js app and it was working in my computer just fine.
I had installed heroku toolbelt and the app was running fine when I ran foreman start.
Deploying the app in heroku seems to be giving me some kind of error when conecting with postgres by using sequelize (I'm not even 100% sure that's the cause of the error, but almost). The app crashes and all I have is the heroku logs:
2014-01-05T11:07:39.850661+00:00 app[web.1]: Servidor escuchando al puerto: 25144
2014-01-05T11:07:39.911641+00:00 app[web.1]:
2014-01-05T11:07:39.912039+00:00 app[web.1]: timers.js:103
2014-01-05T11:07:39.912288+00:00 app[web.1]: if (!process.listeners('uncaughtException').length) throw e;
2014-01-05T11:07:39.913123+00:00 app[web.1]: ^
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.getConnectorManager (/app/node_modules/sequelize/lib/transaction-manager.js:25:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.query (/app/node_modules/sequelize/lib/transaction-manager.js:39:15)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.Sequelize.query (/app/node_modules/sequelize/lib/sequelize.js:310:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/sequelize/lib/query-interface.js:901:40)
2014-01-05T11:07:39.915970+00:00 app[web.1]: TypeError: Cannot call method 'setTypeParser' of undefined
2014-01-05T11:07:39.915970+00:00 app[web.1]: at new module.exports.ConnectorManager (/app/node_modules/sequelize/lib/dialects/postgres/connector-manager.js:19:19)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.CustomEventEmitter.run (/app/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at Timer.list.ontimeout (timers.js:101:19)
2014-01-05T11:07:41.217303+00:00 heroku[web.1]: Process exited with status 1
2014-01-05T11:07:41.234281+00:00 heroku[web.1]: State changed from starting to crashed
The first line ("Servidor escuchando al puerto: XXXX") is actually part of app.js (the main .js file), it's the last few lines:
http.createServer(app).listen(app.get('port'), function(){
console.log('Servidor escuchando al puerto: ' + app.get('port'));
});
As I said before, it runs fine locally (executing foreman start correctly displays it on localhost) but I've had no luck on heroku.
Thanks for any insight and help =)
EDIT: I've managed to trace somewhat the error, seems there is a call to:
pg.types.setTypeParser(20, String)
somewhere in the sequelize module that throws the error since pg.types is undefined
I've checked by simply doing:
console.log(require('pg'));
And it indeed seems there is no field "types"
Is that the way it's meant to be? Am I missing something?
pg.types comes from a dependency of pg:
See package json here:
https://github.com/brianc/node-postgres/blob/master/package.json
This is the package here:
https://www.npmjs.org/package/pg-types
If you don't have it and you installed pg through npm, try removing pg and re-running npm install and see if there are any errors. It should download pg-types tool.
You can see where pg.types specifically is defined here:
https://github.com/brianc/node-postgres/blob/master/lib/index.js

Error: failed to connect to [localhost:27017] when running MEAN app on HEROKU

I'm writing my second MEAN app. The first one was build aggregating the components by hand (I was not aware of MEAN) and hosting it at HEROKU; I attempted to use MONGOOSE but gave up due to problems connecting with the database at HEROKU - it worked fine on my MAC. This time around it works on my MAC but I'm still having connection problems; I do not want to jettison MONGOOSE. At this point all I have is the vanilla MEAN app built off its zip file, the zip file downloaded from the MEAN GitHUB repository. See below for the logs I get from HEROKU:
2013-09-10T01:33:28.045816+00:00 heroku[web.1]: Starting process with command `grunt`
2013-09-10T01:33:29.526090+00:00 app[web.1]: Running "jshint:all" (jshint) task
2013-09-10T01:33:29.567534+00:00 app[web.1]: >> 1 file lint free.
2013-09-10T01:33:29.568809+00:00 app[web.1]:
2013-09-10T01:33:29.568809+00:00 app[web.1]: Running "compass:dist" (compass) task
2013-09-10T01:33:29.573055+00:00 app[web.1]: Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
2013-09-10T01:33:29.574527+00:00 app[web.1]: Warning: Cannot read property 'stdout' of undefined Used --force, continuing.
2013-09-10T01:33:29.574641+00:00 app[web.1]:
2013-09-10T01:33:29.575774+00:00 app[web.1]: Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
2013-09-10T01:33:29.574641+00:00 app[web.1]: Running "compass:dev" (compass) task
2013-09-10T01:33:29.576128+00:00 app[web.1]: Running "concurrent:target" (concurrent) task
2013-09-10T01:33:29.576043+00:00 app[web.1]:
2013-09-10T01:33:30.414023+00:00 app[web.1]: Running "nodemon:dev" (nodemon) task
2013-09-10T01:33:30.511082+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] v0.7.10
2013-09-10T01:33:30.511537+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] to restart at any time, enter `rs`
2013-09-10T01:33:30.511664+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] watching: /app/config
2013-09-10T01:33:30.511664+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] watching: /app/app
2013-09-10T01:33:30.536018+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] Unable to write to temp directory. If you experience problems with file reloading, ensure /tmp is writable.
2013-09-10T01:33:30.550590+00:00 app[web.1]: debugger listening on port 5858
2013-09-10T01:33:30.578354+00:00 app[web.1]: Running "watch" task
2013-09-10T01:33:30.624330+00:00 app[web.1]: Waiting...10 Sep 01:33:30 - [nodemon] reading ignore list
2013-09-10T01:33:31.152639+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-09-10T01:33:31.154862+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-09-10T01:33:31.148967+00:00 app[web.1]: Express app started on port 3000
2013-09-10T01:33:31.152143+00:00 app[web.1]:
2013-09-10T01:33:31.152401+00:00 app[web.1]: events.js:72
2013-09-10T01:33:31.154862+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-09-10T01:33:31.154862+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
Any comments of suggestions would be much welcome. Thanks in advance.
You need to host MongoDB somewhere. There are a number of MongoDB hosting services, MongoHQ and MongoLab the most popular. I have used MongoHQ with good results although I must admit I haven't stressed my system. You can sign up for the free trial (I think you get 512MB), once you have done that, replace your connection string with (you will get all the details when signing up):
'mongodb://username:password#domain:port/dbName'

Heroku Logs - open log referred to in error message

I'm deploying a node.js app to heroku (cedar stack)
I've set the NODE_ENV like this:
heroku config:add NODE_ENV=production
I then do:
git push heroku
However, after starting (i've got a console.log generating the first log entry) the app crashes.
I run:
heroku logs
and get the below error.
How can I open the /app/log/production.log that it's referring to?
app[web.1]: listening on port 32168 within production environment
app[web.1]:
app[web.1]: events.js:48
app[web.1]: throw arguments[1]; // Unhandled 'error' event
app[web.1]: ^
app[web.1]: Error: ENOENT, open '/app/log/production.log'
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
The error you're getting means that it's trying to open '/app/log/production.log' and is unable to do so. So find out where this logging is being attempted and disable or change it.
According to Heroku you should just be sending your application logs to STDOUT:
https://devcenter.heroku.com/articles/logging
So a console.log should be sufficient.

Resources