I'm trying to start Chrome in --headless with defined --user-data-dir switch.
As far as I can understand from the sources, although headless Chrome by default should start in incognito mode, it's disabled when the user-data-dir flag exists:
// Run a browser context in an incognito mode. Enabled by default.
bool incognito_mode;
if (command_line.HasSwitch(switches::kUserDataDir)) {
builder.SetUserDataDir(
command_line.GetSwitchValuePath(switches::kUserDataDir));
builder.SetIncognitoMode(false);
}
But it seems that regardless to that flag no profile data is written to the directory (but the directory is created), very similar to how it behaves in incognito mode.