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
Related
Could not connect to your Ethereum client with the following parameters: - host > 127.0.0.1 - port > 7545 - network_id > * Please check that your Ethereum client: - is running - is accepting RPC connections (i.e., "--rpc" option is used in geth) - is accessible over the network - is properly configured in your Truffle configuration file (truffle-config.js)
Truffle v5.3.9 (core: 5.3.9) Node v16.3.0
This is from this video https://youtu.be/XLahq4qyors?t=1385
AND yes my ganache is opened , my truffle-config.json is configured properly with correct port and all tried other solutions from this work but unfortunately it did not work
My config
require('babel-polyfill');
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
compilers: {
solc: {
optimizer: {
enabled: true,
runs: 200
},
evmVersion: "petersburg"
}
}
}```
We have enabled ACL's and TLS for Consul cluster in our environment. We have disabled the UI as well. But when I use the URL: http://<consul_agent>:8500/v1/coordinate/datacenters. How can disable the URL's as this?
I tested with adding the following to the consulConfig.json:
"ports":{
"http": -1
}
this did not solve the problem.
Apart from the suggestion provided to use "http_config": { "block_endpoints": I am trying to use the ACL Policy if that can solve.
I enabled the ACL's first
I created a policy using the command: consul acl policy create -name "urlblock" -description "Url Block Policy" -rules #service_block.hcl -token <tokenvalue>
contents of the service_block.hcl: service_prefix "/v1/status/leader" { policy = "deny" }
I created a agent token for this using the command: consul acl token create -description "Block Policy Token" -policy-name "urlblock" -token <tokenvalue>
I copied the agent token from the output of the above command and pasted that in the consul_config.json file in the acl -> tokens section as "tokens": { "agent": "<agenttokenvalue>"}
I restarted the consul agents (did the same in the consul client also).
Still I am able to access the endpoint /v1/status/leader. Any ideas as what is wrong with this approach?
That configuration should properly disable the HTTP server. I was able to validate this works using the following config with Consul 1.9.5.
Disabling Consul's HTTP server
Create config.json in the agent's configuration directory which completely disables the HTTP API port.
config.json
{
"ports": {
"http": -1
}
}
Start the Consul agent
$ consul agent -dev -config-file=config.json
==> Starting Consul agent...
Version: '1.9.5'
Node ID: 'ed7f0050-8191-999c-a53f-9ac48fd03f7e'
Node name: 'b1000.local'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: -1, HTTPS: -1, gRPC: 8502, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
...
Note the HTTP port is set to "-1" on the Client Addr line. The port is now inaccessible.
Test connectivity to HTTP API
$ curl localhost:8500
curl: (7) Failed to connect to localhost port 8500: Connection refused
Blocking access to specific API endpoints
Alternatively you can block access to specific API endpoints, without completely disabling the HTTP API, by using the http_config.block_endpoints configuration option.
For example:
Create a config named block-endpoints.json
{
"http_config": {
"block_endpoints": [
"/v1/catalog/datacenters",
"/v1/coordinate/datacenters",
"/v1/status/leader",
"/v1/status/peers"
]
}
}
Start Consul with this config
consul agent -dev -config-file=block-endpoints.json
==> Starting Consul agent...
Version: '1.9.5'
Node ID: '8ff15668-8624-47b5-6e83-7a8bfd715a56'
Node name: 'b1000.local'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: 8502, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
...
In this example, the HTTP API is enabled and listening on port 8500.
Test connectivity to HTTP API
If you issue a request to one of the blocked endpoints, the following error will be returned.
$ curl localhost:8500/v1/status/peers
Endpoint is blocked by agent configuration
However, access to other endpoints are still permitted.
$ curl localhost:8500/v1/agent/members
[
{
"Name": "b1000.local",
"Addr": "127.0.0.1",
"Port": 8301,
"Tags": {
"acls": "0",
"build": "1.9.5:3c1c2267",
"dc": "dc1",
"ft_fs": "1",
"ft_si": "1",
"id": "6d157a1b-c893-3903-9037-2e2bd0e6f973",
"port": "8300",
"raft_vsn": "3",
"role": "consul",
"segment": "",
"vsn": "2",
"vsn_max": "3",
"vsn_min": "2",
"wan_join_port": "8302"
},
"Status": 1,
"ProtocolMin": 1,
"ProtocolMax": 5,
"ProtocolCur": 2,
"DelegateMin": 2,
"DelegateMax": 5,
"DelegateCur": 4
}
]
I would like to apply PWA in nuxt(#2.3.4) web application.
The operating system is OSX latest.
So I have installed #nuxtjs/pwa and add some config to nuxt.config.js.
These are what I have added
module.exports = {
...
modules: [
['#nuxtjs/pwa', {icon : false}]
],
workbox : {
dev: true,
debug: true
},
manifest : {
viewport: 'width=device-width, initial-scale=1',
theme_color: '#3B8070'
},
...
}
And build with NODE_ENV=production and start.
I am able to find sw.js in localhost:9000, but it is not available with
local.jy.net:9000.
I was expecting the same result since I register that hostname on my hosts file.
Here is what I have in /private/etc/hosts.
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 Juneui-MacBook-Pro.local
127.0.0.1 local.jy.net aad901eb546340cc9a69b0b030b124fc.jy.net
How could I make #nuxtjs/pwa refers system hosts variables?
If you need more information, add reply then I will provide as possible as I can. Thanks.
The #nuxtjs/pwa package is looking for the build.publicPath option: https://github.com/nuxt-community/pwa-module/blob/9f27d5cdae0e0341d6d4b4f6814f91db6eab1432/packages/manifest/index.js#L24
Adding this option to your nuxt.config.js should do the trick:
module.exports = {
...
modules: [
['#nuxtjs/pwa', {icon : false}]
],
workbox : {
dev: true,
debug: true
},
manifest : {
viewport: 'width=device-width, initial-scale=1',
theme_color: '#3B8070'
},
build: {
publicPath: '//local.jy.net:9000/pwa/',
}
...
}
You can find more information about the publicPath property here: https://nuxtjs.org/api/configuration-build#publicpath
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.
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.