feat(chromium): flags for clearing cache/cookies between each conversion (#756)

This commit is contained in:
Julien Neuhart
2023-12-14 22:06:13 +01:00
committed by GitHub
parent 64af65b0e7
commit 93b9ac2d13
5 changed files with 118 additions and 2 deletions

View File

@@ -481,6 +481,72 @@ func TestChromiumBrowser_pdf(t *testing.T) {
expectError: true,
expectedError: ErrConsoleExceptions,
},
{
scenario: "clear cache",
browser: newChromiumBrowser(
browserArguments{
binPath: os.Getenv("CHROMIUM_BIN_PATH"),
wsUrlReadTimeout: 5 * time.Second,
allowList: regexp.MustCompile(""),
denyList: regexp.MustCompile(""),
clearCache: true,
},
),
fs: func() *gotenberg.FileSystem {
fs := gotenberg.NewFileSystem()
err := os.MkdirAll(fs.WorkingDirPath(), 0o755)
if err != nil {
t.Fatalf(fmt.Sprintf("expected no error but got: %v", err))
}
err = os.WriteFile(fmt.Sprintf("%s/index.html", fs.WorkingDirPath()), []byte("<h1>Clear cache</h1>"), 0o755)
if err != nil {
t.Fatalf("expected no error but got: %v", err)
}
return fs
}(),
noDeadline: false,
start: true,
expectError: false,
expectedLogEntries: []string{
"clear cache",
},
},
{
scenario: "clear cookies",
browser: newChromiumBrowser(
browserArguments{
binPath: os.Getenv("CHROMIUM_BIN_PATH"),
wsUrlReadTimeout: 5 * time.Second,
allowList: regexp.MustCompile(""),
denyList: regexp.MustCompile(""),
clearCookies: true,
},
),
fs: func() *gotenberg.FileSystem {
fs := gotenberg.NewFileSystem()
err := os.MkdirAll(fs.WorkingDirPath(), 0o755)
if err != nil {
t.Fatalf(fmt.Sprintf("expected no error but got: %v", err))
}
err = os.WriteFile(fmt.Sprintf("%s/index.html", fs.WorkingDirPath()), []byte("<h1>Clear cookies</h1>"), 0o755)
if err != nil {
t.Fatalf("expected no error but got: %v", err)
}
return fs
}(),
noDeadline: false,
start: true,
expectError: false,
expectedLogEntries: []string{
"clear cookies",
},
},
{
scenario: "disable JavaScript",
browser: newChromiumBrowser(
@@ -1024,6 +1090,8 @@ func TestChromiumBrowser_pdf(t *testing.T) {
start: true,
expectError: false,
expectedLogEntries: []string{
"cache not cleared",
"cookies not cleared",
"JavaScript not disabled",
"no extra HTTP headers",
"navigate to",