Merge pull request #6222 from fourcube/fix/slow-headless-start-and-shutdown

fix: improve headless engine startup and shutdown
This commit is contained in:
Dogan Can Bakir 2025-05-19 16:42:38 +03:00 committed by GitHub
commit 160eab998c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,16 +15,15 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/types"
fileutil "github.com/projectdiscovery/utils/file"
osutils "github.com/projectdiscovery/utils/os"
processutil "github.com/projectdiscovery/utils/process"
)
// Browser is a browser structure for nuclei headless module
type Browser struct {
customAgent string
tempDir string
previousPIDs map[int32]struct{} // track already running PIDs
engine *rod.Browser
options *types.Options
customAgent string
tempDir string
engine *rod.Browser
options *types.Options
launcher *launcher.Launcher
// use getHTTPClient to get the http client
httpClient *http.Client
httpClientOnce *sync.Once
@ -36,7 +35,6 @@ func New(options *types.Options) (*Browser, error) {
if err != nil {
return nil, errors.Wrap(err, "could not create temporary directory")
}
previousPIDs := processutil.FindProcesses(processutil.IsChromeProcess)
chromeLauncher := launcher.New().
Leakless(false).
@ -110,8 +108,8 @@ func New(options *types.Options) (*Browser, error) {
engine: browser,
options: options,
httpClientOnce: &sync.Once{},
launcher: chromeLauncher,
}
engine.previousPIDs = previousPIDs
return engine, nil
}
@ -143,6 +141,6 @@ func (b *Browser) getHTTPClient() (*http.Client, error) {
// Close closes the browser engine
func (b *Browser) Close() {
b.engine.Close()
b.launcher.Kill()
os.RemoveAll(b.tempDir)
processutil.CloseProcesses(processutil.IsChromeProcess, b.previousPIDs)
}