chrome-launcher
chrome-launcher copied to clipboard
Question: is it possible to launch Chrome in incognito mode and use with lighthouse-cli?
I have tried:
chromeFlags: ['--incognito'],
but this seems to open up chrome in both normal and incognito mode at the same time and lighthouse then uses normal mode to perform audits (incognito window stays empty if not headless)
whole code:
const launchChromeAndRunLighthouse = (
url,
opts = {
chromeFlags: ['--incognito'],
},
config = defaultConfig,
) =>
new Promise(resolve => {
chromeLauncher.launch({ chromeFlags: opts.chromeFlags }).then(chrome => {
opts.port = chrome.port;
lighthouse(url, opts, config).then(results => chrome.kill().then(() => resolve(results)));
});
});
launching Chrome Version 76.0.3787.0 (Official Build) canary (64-bit)
but this seems to open up chrome in both normal and incognito mode at the same time and lighthouse then uses normal mode to perform audits (incognito window stays empty if not headless)
yup, i can confirm this.
There may be a way to fix this in Ligthouse:
messy lighthouse diff
diff --git a/lighthouse-core/gather/connections/cri.js b/lighthouse-core/gather/connections/cri.js
index d8de97357..b52d0fc32 100644
--- a/lighthouse-core/gather/connections/cri.js
+++ b/lighthouse-core/gather/connections/cri.js
@@ -34,8 +34,13 @@ class CriConnection extends Connection {
* @return {Promise<void>}
*/
connect() {
- return this._runJsonCommand('new')
- .then(response => this._connectToSocket(/** @type {LH.DevToolsJsonTarget} */(response)))
+ // return this.sendCommand('Target.createTarget')
+ return this._runJsonCommand('json/version')
+ .then(response => this._connectToSocket(/** @type {LH.DevToolsVersion} */(response)))
+ .then(async _ => {
+ const target = await this.sendCommand('Target.createTarget');
+ return this._connectToSocket(target);
+ })
.catch(_ => {
// COMPAT: headless didn't support `/json/new` before m59. (#970, crbug.com/699392)
// If no support, we fallback and reuse an existing open tab
diff --git a/types/externs.d.ts b/types/externs.d.ts
index 5b8a42438..d5cce9c30 100644
--- a/types/externs.d.ts
+++ b/types/externs.d.ts
@@ -369,6 +369,15 @@ declare global {
url: string;
webSocketDebuggerUrl: string;
}
+
+ export interface DevToolsVersion {
+ "Browser": string
+ "Protocol-Version": string
+ "User-Agent": string
+ "V8-Version": string
+ "WebKit-Version": string
+ "webSocketDebuggerUrl": string
+ }
}
interface Window {
... however i'm curious about the usecase. by default chrome-launcher is using fresh chrome profiles (via --user-data-dir) and that should be fairly equivalent to incognito. is there a reason to need real incognito?
@paulirish use case was I believe to not have shared cookies in between launches
I was using chrome launcher 0.11.2
at that time
Same issue and usecase for me. Is there no solution for this?
not have shared cookies in between launches
Lighthouse's default usage of chrome-launcher
already accomplishes this by using a fresh chrome profile.
Without a convincing use case, closing this.