Problem :
I am running chromium headless with Selenium.
When I run a bunch of sessions I end up with a bunch of tmp files in /tmp
drwx------ 3 nick nick 4.0K Jul 28 05:00 .org.chromium.Chromium.OpPRkQ
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.tAwQZu
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.JiqQZu
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.7Vce75
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.r5ITam
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.eWgdRV
drwx------ 3 nick nick 4.0K Jul 29 00:00 .org.chromium.Chromium.8TITam
drwx------ 3 nick nick 4.0K Jul 29 05:00 .org.chromium.Chromium.aeuzcU
drwx------ 3 nick nick 4.0K Jul 29 05:00 .org.chromium.Chromium.cBHew4
What is Google Chrome command line switch I can set to choose a different path for these directories? I cannot use /tmp
because the root disk doesn’t have much disk space on the cloud.
Is there a way to have these directories automatically deleted upon shutdown of the chrome process?
See https://peter.sh/experiments/chromium-command-line-switches/
Solution :
Wow it took me a long time to find this:
There is no command line argument that does this. But environment variable can.
Here is the relevant chromedriver code:
https://chromium.googlesource.com/chromium/chromium/+/master/base/file_util_posix.cc
#if !defined(OS_MACOSX)
bool GetTempDir(FilePath* path) {
const char* tmp = getenv("TMPDIR");
if (tmp)
*path = FilePath(tmp);
else
#if defined(OS_ANDROID)
return PathService::Get(base::DIR_CACHE, path);
#else
*path = FilePath("/tmp");
#endif
return true;
}
So for linux, you can just set a TMPDIR environment variable in the Chrome session to do this.
So in selenium, you have to do this:
ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("driver_linux/chromedriver"))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("TMPDIR", "/some/other/tmp/dir")).build();