Can not access Chrome headless debug - google-chrome

I am running a angular 5 unit test on a headless server in Karma and Jasmine. I am using chrome headless to run the tests.
I am not able to access Chrome's debug mode when using with --remote-debugging-port=9223. I tried with http://35.1.28.84:9223 in my remote chrome url.
I made sure the all interfaces are listening with host: '0.0.0.0'. I made sure the port was open also.
How come I am not able to access chrome's debugger remotely?
START:
29 03 2018 15:38:05.480:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
29 03 2018 15:38:05.482:INFO [launcher]: Launching browser MyHeadlessChrome with unlimited concurrency
29 03 2018 15:38:05.497:INFO [launcher]: Starting browser ChromeHeadless
29 03 2018 15:38:18.487:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket pfKmImL3pGU9ibL7AAAA with id 10485493
headless-karma.conf.js
module.exports = function(config) {
config.set({
host: '0.0.0.0',
basePath: '',
frameworks: ['jasmine', '#angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-mocha-reporter'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('#angular/cli/plugins/karma')
],
reporters: ['mocha'],
port: 9876, // karma web server port
colors: true,
angularCli: {
environment: 'dev'
},
browsers: ['MyHeadlessChrome'],
customLaunchers: {
MyHeadlessChrome: {
base: 'ChromeHeadless',
flags: [
'--disable-translate',
'--disable-extensions',
'--no-first-run',
'--disable-background-networking',
'--remote-debugging-port=9223',
]
}
},
autoWatch: false,
singleRun: true,
concurrency: Infinity
});
};
one#work:~/github/MCTS.UI (dh/headless-unittests)
$ google-chrome --version
Google Chrome 64.0.3282.167
one#work:~/github/MCTS.UI (dh/headless-unittests)
$ google-chrome-stable --version
Google Chrome 64.0.3282.167

There is another parameter you need to supply to chrome:
--remote-debugging-address=0.0.0.0
Use the given address instead of the default loopback for accepting remote debugging connections. Should be used together with --remote-debugging-port. Note that the remote debugging protocol does not perform any authentication, so exposing it too widely can be a security risk.

Related

How to manually recreate the bootstrap client certificate for OpenShift 3.11 master?

Our origin-node.service on the master node fails with:
root#master> systemctl start origin-node.service
Job for origin-node.service failed because the control process exited with error code. See "systemctl status origin-node.service" and "journalctl -xe" for details.
root#master> systemctl status origin-node.service -l
[...]
May 05 07:17:47 master origin-node[44066]: bootstrap.go:195] Part of the existing bootstrap client certificate is expired: 2020-02-20 13:14:27 +0000 UTC
May 05 07:17:47 master origin-node[44066]: bootstrap.go:56] Using bootstrap kubeconfig to generate TLS client cert, key and kubeconfig file
May 05 07:17:47 master origin-node[44066]: certificate_store.go:131] Loading cert/key pair from "/etc/origin/node/certificates/kubelet-client-current.pem".
May 05 07:17:47 master origin-node[44066]: server.go:262] failed to run Kubelet: cannot create certificate signing request: Post https://lb.openshift-cluster.mydomain.com:8443/apis/certificates.k8s.io/v1beta1/certificatesigningrequests: EOF
So it seems that kubelet-client-current.pem and/or kubelet-server-current.pem contains an expired certificate and the service tries to create a CSR using an endpoint which is probably not yet available (because the master is down). We tried redeploying the certificates according to the OpenShift documentation Redeploying Certificates, but this fails while detecting an expired certificate:
root#master> ansible-playbook -i /etc/ansible/hosts openshift-master/redeploy-openshift-ca.yml
[...]
TASK [openshift_certificate_expiry : Fail when certs are near or already expired] *******************************************************************************************************************************************
fatal: [master.openshift-cluster.mydomain.com]: FAILED! => {"changed": false, "msg": "Cluster certificates found to be expired or within 60 days of expiring. You may view the report at /root/cert-expiry-report.20200505T042754.html or /root/cert-expiry-report.20200505T042754.json.\n"}
[...]
root#master> cat /root/cert-expiry-report.20200505T042754.json
[...]
"kubeconfigs": [
{
"cert_cn": "O:system:cluster-admins, CN:system:admin",
"days_remaining": -75,
"expiry": "2020-02-20 13:14:27",
"health": "expired",
"issuer": "CN=openshift-signer#1519045219 ",
"path": "/etc/origin/node/node.kubeconfig",
"serial": 27,
"serial_hex": "0x1b"
},
{
"cert_cn": "O:system:cluster-admins, CN:system:admin",
"days_remaining": -75,
"expiry": "2020-02-20 13:14:27",
"health": "expired",
"issuer": "CN=openshift-signer#1519045219 ",
"path": "/etc/origin/node/node.kubeconfig",
"serial": 27,
"serial_hex": "0x1b"
},
[...]
"summary": {
"expired": 2,
"ok": 22,
"total": 24,
"warning": 0
}
}
There is a guide for OpenShift 4.4 for Recovering from expired control plane certificates, but that does not apply for 3.11 and we did not find such a guide for our version.
Is it possible to recreate the expired certificates without a running master node for 3.11? Thanks for any help.
OpenShift Ansible: https://github.com/openshift/openshift-ansible/releases/tag/openshift-ansible-3.11.153-2
Update 2020-05-06: I also executed redeploy-certificates.yml, but it fails at the same TASK:
root#master> ansible-playbook -i /etc/ansible/hosts playbooks/redeploy-certificates.yml
[...]
TASK [openshift_certificate_expiry : Fail when certs are near or already expired] ******************************************************************************
Wednesday 06 May 2020 04:07:06 -0400 (0:00:00.909) 0:01:07.582 *********
fatal: [master.openshift-cluster.mydomain.com]: FAILED! => {"changed": false, "msg": "Cluster certificates found to be expired or within 60 days of expiring. You may view the report at /root/cert-expiry-report.20200506T040603.html or /root/cert-expiry-report.20200506T040603.json.\n"}
Update 2020-05-11: Running with -e openshift_certificate_expiry_fail_on_warn=False results in:
root#master> ansible-playbook -i /etc/ansible/hosts -e openshift_certificate_expiry_fail_on_warn=False playbooks/redeploy-certificates.yml
[...]
TASK [Wait for master API to come back online] *****************************************************************************************************************
Monday 11 May 2020 03:48:56 -0400 (0:00:00.111) 0:02:25.186 ************
skipping: [master.openshift-cluster.mydomain.com]
TASK [openshift_control_plane : restart master] ****************************************************************************************************************
Monday 11 May 2020 03:48:56 -0400 (0:00:00.257) 0:02:25.444 ************
changed: [master.openshift-cluster.mydomain.com] => (item=api)
changed: [master.openshift-cluster.mydomain.com] => (item=controllers)
RUNNING HANDLER [openshift_control_plane : verify API server] **************************************************************************************************
Monday 11 May 2020 03:48:57 -0400 (0:00:00.945) 0:02:26.389 ************
FAILED - RETRYING: verify API server (120 retries left).
FAILED - RETRYING: verify API server (119 retries left).
[...]
FAILED - RETRYING: verify API server (1 retries left).
fatal: [master.openshift-cluster.mydomain.com]: FAILED! => {"attempts": 120, "changed": false, "cmd": ["curl", "--silent", "--tlsv1.2", "--max-time", "2", "--cacert", "/etc/origin/master/ca-bundle.crt", "https://lb.openshift-cluster.mydomain.com:8443/healthz/ready"], "delta": "0:00:00.182367", "end": "2020-05-11 03:51:52.245644", "msg": "non-zero return code", "rc": 35, "start": "2020-05-11 03:51:52.063277", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
root#master> systemctl status origin-node.service -l
[...]
May 11 04:23:28 master.openshift-cluster.mydomain.com origin-node[109972]: E0511 04:23:28.077964 109972 bootstrap.go:195] Part of the existing bootstrap client certificate is expired: 2020-02-20 13:14:27 +0000 UTC
May 11 04:23:28 master.openshift-cluster.mydomain.com origin-node[109972]: I0511 04:23:28.078001 109972 bootstrap.go:56] Using bootstrap kubeconfig to generate TLS client cert, key and kubeconfig file
May 11 04:23:28 master.openshift-cluster.mydomain.com origin-node[109972]: I0511 04:23:28.080555 109972 certificate_store.go:131] Loading cert/key pair from "/etc/origin/node/certificates/kubelet-client-current.pem".
May 11 04:23:28 master.openshift-cluster.mydomain.com origin-node[109972]: F0511 04:23:28.130968 109972 server.go:262] failed to run Kubelet: cannot create certificate signing request: Post https://lb.openshift-cluster.mydomain.com:8443/apis/certificates.k8s.io/v1beta1/certificatesigningrequests: EOF
[...]
I have this same case in customer environment, this error is because the certified was expiry, i "cheated" changing da S.O date before the expiry date. And the origin-node service started in my masters:
systemctl status origin-node
● origin-node.service - OpenShift Node
Loaded: loaded (/etc/systemd/system/origin-node.service; enabled; vendor preset: disabled)
Active: active (running) since Sáb 2021-02-20 20:22:21 -02; 6min ago
Docs: https://github.com/openshift/origin
Main PID: 37230 (hyperkube)
Memory: 79.0M
CGroup: /system.slice/origin-node.service
└─37230 /usr/bin/hyperkube kubelet --v=2 --address=0.0.0.0 --allow-privileged=true --anonymous-auth=true --authentication-token-webhook=true --authentication-token-webhook-cache-ttl=5m --authorization-mode=Webhook --authorization-webhook-c...
Você tem mensagem de correio em /var/spool/mail/okd
The openshift_certificate_expiry role uses the openshift_certificate_expiry_fail_on_warn variable to determine if the playbook should fail when the days left are less than openshift_certificate_expiry_warning_days.
So try running the redeploy-certificates.yml with this additional variable set to "False":
ansible-playbook -i /etc/ansible/hosts -e openshift_certificate_expiry_fail_on_warn=False playbooks/redeploy-certificates.yml

E/launcher - unknown error: Chrome failed to start: exited abnormally, Protractor

I am new to protractor ,as well as automation testing. I ran my conf.js file but the process terminate with below error related to chorme
error message
$$> protractor conf.js
[08:38:14] I/launcher - Running 1 instances of WebDriver
[08:38:14] I/direct - Using ChromeDriver directly...
**
[08:39:14] E/launcher - unknown error: Chrome failed to start: exited
abnormally (Driver info: chromedriver=2.37.544315
(730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux
3.10.0-1062.1.1.el7.x86_64 x86_64) [08:39:14] E/launcher - WebDriverError: unknown error: Chrome failed to start: exited
abnormally (Driver info: chromedriver=2.37.544315
(730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux
3.10.0-1062.1.1.el7.x86_64 x86_64)
**
at Object.checkLegacyResponse (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: WebDriver.createSession()
at Function.createSession (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
at Function.createSession (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/chrome.js:761:15)
at Direct.getNewDriver (/usr/lib/node_modules/protractor/built/driverProviders/direct.js:77:33)
at Runner.createBrowser (/usr/lib/node_modules/protractor/built/runner.js:195:43)
at q.then.then (/usr/lib/node_modules/protractor/built/runner.js:339:29)
at _fulfilled (/usr/lib/node_modules/protractor/node_modules/q/q.js:834:54)
at /usr/lib/node_modules/protractor/node_modules/q/q.js:863:30
at Promise.promise.promiseDispatch (/usr/lib/node_modules/protractor/node_modules/q/q.js:796:13)
at /usr/lib/node_modules/protractor/node_modules/q/q.js:556:49
at runSingle (/usr/lib/node_modules/protractor/node_modules/q/q.js:137:13)
[08:39:14] E/launcher - Process exited with error code 199
I have tried all possible solutions ,
From upgrading chrome to 59x version to downgrading it to 2.37 version
adding extras like below to conf.js file
directConnect: true,
useAllAngular2AppRoots:true,
capabilities: {
browserName: 'chrome',
chromeOptions: {
'args':['--no-sandbox']
}
}
conf.js
exports.config = {
directConnect: true,
framework: 'jasmine',
// seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
'args': ['--no-sandbox']
}
},
useAllAngular2AppRoots: true
}
could someone please help me make this work.
Thank you
(new to post questions on stackoverflow as well :b)
The main error here is that your chrome is failing to start a session. This happens if the chrome version being downloaded is the latest beta version. This is a bug in the latest protractor package which is being looked into for the protractor 6 release with backwards compatibility with webdriver-manager. For this you will have to fix the version of the chromedriver.
How are you running your webdriver manager update? Do not use the globally installed protractor to run your tests, use the protractor from node modules. Do the same thing when using webdriver manager update. Use a fix version like ./node_modules/protractor/bin/webdriver-manager update --standalone --versions.standalone=3.8.0 --chrome --versions.chrome=78.0.3904.97
Add this to your scripts in package.json.
Add jasmine options in your configuration file:
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 260000,
isVerbose: true,
includeStackTrace: true,
}
I don't think the latter would help but try updating the webdriver manager with the fix version and let me know how that goes.

VSCode debugger can not connect to puppeteer instance run by Karma

I have Angular frontend tests run with Karma and Jasmine that I want to debug with Visual Studio Code. The tests are run in a puppeteer instance.
When the debugger tries to connect, it times out, and tells me the socket hung up.
When I visit http://localhost:9333/ where my puppeteer instance is listening I get an ERR_EMPTY_RESPONSE.
Connecting the debugger to a headless Chrome instance started with chrome --headless --remote-debugging-port=9333 works fine.
My karma.conf.js:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-spec-reporter'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('#angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
mime: {
'text/x-typescript': ['ts', 'tsx'],
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true,
},
angularCli: {
environment: 'dev',
},
reporters:
config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
debug: true,
flags: ['--no-sandbox', '--remote-debugging-port=9333'],
},
},
browserNoActivityTimeout: 120000,
singleRun: false,
});
};
The relevant part of my launch.json:
{
"type": "chrome",
"request": "attach",
"name": "Debug Frontend Tests",
"address": "localhost",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceFolder}/client/web",
}
TL,DR: Add the flag '--remote-debugging-address=0.0.0.0' to your customLaunchers' flags array.
It turns out that adding the '--remote-debugging-port=9333' flag opens the port only for clients on the local machine. Since puppeteer runs in a Docker container, it views VSCode as a remote client and denies connection.
Running lsof -i -P -n | grep LISTEN inside the container reveals that Chrome opens the port 9333 only for local clients:
root#b6ff203497dc:~# lsof -i -P -n | grep LISTEN
node 247 root 21u IPv4 224919 0t0 TCP *:9876 (LISTEN)
chrome 260 root 137u IPv4 229390 0t0 TCP 127.0.0.1:9333 (LISTEN)
Additionally adding the flag '--remote-debugging-address=0.0.0.0' makes Chrome open the port for all IP addresses.
root#b6ff203497dc:~# lsof -i -P -n | grep LISTEN
node 247 root 21u IPv4 224919 0t0 TCP *:9876 (LISTEN)
chrome 260 root 137u IPv4 229390 0t0 TCP *:9333 (LISTEN)
Now VSCode can connect.
The crucial hints were given by:
Chrome remote debugging from another machine
https://github.com/puppeteer/puppeteer/issues/5063#issuecomment-561595885

Unable to Attach remote debugger to Chrome headless in Selenium WebDriver

I'm running my E2E test cases using Selenium WebDriver with Chrome headless. this configuration working fine and able run test case.
My code looks like this:
const options = {
desiredCapabilities: {
port: PORT,
browserName: 'chrome',
chromeOptions: {
args: ['disable-infobars'
,'headless',
'disable-gpu',
],
//binary: '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome'
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
host: envConfig.seleniumUrl,
deprecationWarnings: false
};
this.browser = webdriverio
.remote(options)
.init()
.url(envConfig.appUrl)
.timeouts('script', 35000)
.timeouts('implicit', 35000);
Some of my test case failing so i am trying to attach chrome debugger using chrome launch option
--remote-debugging-port=9222
https://developers.google.com/web/updates/2017/04/headless-chrome
After adding remote debugging port flag My E2E failing and unable to start
const options = {
desiredCapabilities: {
port: PORT,
browserName: 'chrome',
chromeOptions: {
args: ['disable-infobars'
,'headless',
'disable-gpu',
'--remote-debugging-port=5552'
],
//binary: '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome'
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
host: envConfig.seleniumUrl,
deprecationWarnings: false
};
Error is
chrome not reachable
(Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.09 seconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'xxxxxx', ip: 'xxxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_161'
Driver info: driver.version: unknownError: An unknown server-side error occurred while processing the command.
at end() - hooks.js:47:25
how to fix this initialization issue and how to attach chrome dev tools with headless browser.

Karma singleRun not quitting automatically

My karma test runner isn't automatically quitting after tests have finished, even though my config has singleRun set to true and I'm not auto-watching files, which should make the test runner run once, then quit according to the docs.
module.exports = function(config) {
config.set({
basePath: '',
browsers: ['PhantomJS'],
frameworks: ['browserify', 'jasmine'],
files: [
{ pattern: 'test/*.js', watched: false }
],
preprocessors: {
'static/js/src/*.js': ['browserify'],
'test/*.js': ['browserify']
},
browserify: {
debug: true,
transform: [["babelify", { "presets": ["es2015"] }]]
},
colors: true,
reporters: ['progress'],
singleRun: true,
autoWatch: false
});
};
When run via my gulp test command:
gulp.task('test', function(done) {
new Karma({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
the tests complete:
[09:18:38] Using gulpfile ~/static-projects/tic-tac-toe-es6/gulpfile.js
[09:18:38] Starting 'test'...
04 02 2016 09:18:40.502:INFO [framework.browserify]: bundle built
04 02 2016 09:18:40.509:INFO [karma]: Karma v0.13.19 server started at http://localhost:9876/
04 02 2016 09:18:40.523:INFO [launcher]: Starting browser PhantomJS
04 02 2016 09:18:41.157:INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket /#xIZCPzrCyB2xljZ7AAAA with id 64233425
PhantomJS 1.9.8 (Linux 0.0.0): Executed 9 of 9 SUCCESS (0.042 secs / 0.003 secs)
[09:18:41] Finished 'test' after 3.1 s
However, I have to manually quit the test runner via Ctrl + c. What am I doing wrong?
I'm having this same problem. There are various threads that elude to this problem with various fixes claimed for this:
https://github.com/karma-runner/gulp-karma/issues/3
https://github.com/karma-runner/karma/issues/1035
However, as far as I can tell this is still an issue (or maybe it's resurfaced?). The only way I've found to successfully execute karma from grunt is by spawning a child process to start karma.
var spawn = require('child_process').spawn;
gulp.task('test', function(done) {
spawn('karma', ['start', __dirname + '/karma.conf.js'], { stdio : 'inherit' });
});