How to disable throttling in Lighthouse programmaticaly? - node.js

As per question title, how can I disable any throttling when using Lighthouse programmatically in NodeJS?

For v3 it's not working like this but as described here
https://developers.google.com/web/tools/lighthouse/v3/migration
e.g. like:
let opts = {
...
throttlingMethod: 'provided',
throttling: {
throughputKbps: 8000,
downloadThroughputKbps: 8000,
uploadThroughputKbps: 2000
}
};

this should help :(tested on lighthouse 2.9.4 )
lhr = await lighthouse(url, {
port: (new URL(browser.wsEndpoint())).port,
output: 'json',
logLevel: 'info',
disableDeviceEmulation: true,
disableCpuThrottling: true,
disableNetworkThrottling: true
});

Related

Can't send log from Hapi-Pino to Elasticsearch

I'm building server for a website use hapi and hapi-pino for logging.
I want to analyze log (about status code, route, timestamp) for some business purpose. I use elasticsearch and kibana to do it
Between hapi-pino and Elasticsearch, I try to use pino-elasticsearch to send log. However, it didn't work, elasticsearch didn't get anything
This is my code for registering hapi-pino:
const streamToElastic = PinoElasticsearch({
index: 'api',
type: 'log',
consistency: 'one',
node: 'http://elastic:changeme#localhost:9200',
'es-version': 6,
'bulk-size': 200,
ecs: true
});
await server.register({
plugin: HapiPino,
options: {
logPayload: true,
prettyPrint: process.env.NODE_ENV !== 'production',
redact: {
paths: ['req.headers', 'payload.user.password', 'payload.file'],
remove: true
},
stream: streamToElastic
}
});
Thanks for any helps and sorry about my poor English!

prevent ffmpeg from opening console window

I have a node/express server which is used to give streams from IP camera to a website. Everything is working well. I run that webserver with PM2 on a windows server.
The problem : for each stream I have a windows console opening with just nothing logged in. The console reopen when I try to close it.
Is there a way to prevent those console to open ?
Here is the related node.js code :
const { NodeMediaServer } = require('node-media-server');
private _initiate_streams(): void{
DatabaseProvider.instance.camerasDao.getCamerasList().pipe(
take(1)
).subscribe(
(databaseReadOperationResult: DatabaseReadOperationResult<ICamera[]>) => {
if (databaseReadOperationResult.successful === true){
const cameras = databaseReadOperationResult.result;
const tasks = [];
cameras.forEach( camera => {
tasks.push(
{
app : config.get('media_server.app_name'),
mode: 'static',
edge: camera.rtsp_url,
name: camera.stream_name,
rtsp_transport: 'tcp'
}
)
});
const configMediaServer = {
logType: 3, // 3 - Log everything (debug)
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30
},
http: {
port: config.get('media_server.port'),
allow_origin: '*'
},
auth: {
play: true,
api: true,
publish: true,
secret: config.get('salt'),
api_user: 'user',
api_pass: 'password',
},
relay: {
ffmpeg: 'C:\\FFmpeg\\bin\\ffmpeg.exe',
tasks: tasks
}
};
var nms = new NodeMediaServer(configMediaServer)
nms.run();
} else {
// catch exception
}
}
);
}

Accessing Loopback config data from middleware

Say we are in Loopback middleware, such as
app.use(function(req,res,next){
// I am not sure what key to use here in the getter...
const config = app.get('?');
});
I want to access the overall config that Loopback is using.
I tried:
const config = app.get('config');
const config = app.get('env');
const config = app.get('datasources');
nothing gives me quite what I want.
Interestingly, this gives me:
console.log(app.get('restApiRoot'));
=> '/api'
so that's a clue to what's going on, but I want to get the parent object(s) for the above data.
how can we access the configuration that Loopback has loaded. The configuration of course varies by environment variables etc.
I want to log what datasources.x.js file was loaded and what config.x.js file was loaded, and any other server configuration info I can capture.
Having a lot of trouble figuring out how to do this.
This seems to be the same question I have:
https://github.com/strongloop/loopback/issues/1526
but they point me to the void that is Google Groups and I searched through there and couldn't find what the answer to this question.
This behavior is actually inherited from Express.
The entire config is stored in the app.settings object, with app.get(key) and app.set(key,value) just acting as getter/setter.
Doing console.log(app.settings); (in server/server.js for instance) it on a fresh loopback install returns the following:
{ 'x-powered-by': true,
etag: 'weak',
'etag fn': [Function: wetag],
env: 'development',
'query parser': 'extended',
'query parser fn': [Function: parseExtendedQueryString],
'subdomain offset': 2,
'trust proxy': false,
'trust proxy fn': [Function: trustNone],
view: [Function: View],
views: 'C:\\Users\\*******\\Documents\\GitHub\\lbtest\\views',
'jsonp callback name': 'callback',
host: '0.0.0.0',
port: 3000,
restApiRoot: '/api',
remoting:
{ context: { enableHttpContext: false },
rest: { normalizeHttpPath: false, xml: false },
json: { strict: false, limit: '100kb' },
urlencoded: { extended: true, limit: '100kb' },
cors: false,
errorHandler: { disableStackTrace: false } },
legacyExplorer: false,
'loopback-component-explorer': { mountPath: '/explorer' },
url: 'http://localhost:3000/' }

Start chrome & firefox with proxy using webdriverio in nodejs

How can I open a browser session with proxy set through the options(/desired capabilities) using WebDriverIO in NodeJs. I use this code for setting proxy, but it stopped working. The browser opens without the proxy and will not perform any further actions.
options = {
desiredCapabilities: {
browserName: 'firefox',
proxy: {
proxyType: 'manual',
httpProxy: '127.0.0.11:80'
}
}
};
client = webdriverio.remote(options).init();
I believe this code should work:
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'firefox'
, proxy: {
proxyType: 'MANUAL'
, httpProxy: '127.0.0.11:80'
}
}
};
client = webdriverio.remote(options).init();
Reference: https://github.com/webdriverio/webdriverio/issues/324

intern.js and Browserstack

Intern.js is a great testrunner but it only appears to work with SauceLabs. My company already uses BrowserStack and are very happy with it. I was wondering if anyone has been able to integrate Intern.js with BrowserStack and if so how?
You should be able to use BrowserStack with the following Intern configuration for Intern 1:
define({
capabilities: {
'browserstack.user': 'your-username',
'browserstack.key': 'your-access-key'
},
webdriver: {
host: 'hub.browserstack.com'
},
useSauceConnect: false
});
or this configuration for Intern 2:
define({
tunnel: 'BrowserStackTunnel',
tunnelOptions: {
username: 'your-username', // or use env var BROWSERSTACK_USERNAME
accessKey: 'your-access-key' // or use env var BROWSERSTACK_ACCESS_KEY
}
});
These settings work for me:
tunnel: 'BrowserStackTunnel',
webdriver: {
username: 'your-useranme',
accessKey: 'your-access-key',
},

Resources