mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 01:25:25 +00:00
Merge pull request #6222 from fourcube/fix/slow-headless-start-and-shutdown
fix: improve headless engine startup and shutdown
This commit is contained in:
commit
160eab998c
@ -15,16 +15,15 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||||
fileutil "github.com/projectdiscovery/utils/file"
|
fileutil "github.com/projectdiscovery/utils/file"
|
||||||
osutils "github.com/projectdiscovery/utils/os"
|
osutils "github.com/projectdiscovery/utils/os"
|
||||||
processutil "github.com/projectdiscovery/utils/process"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Browser is a browser structure for nuclei headless module
|
// Browser is a browser structure for nuclei headless module
|
||||||
type Browser struct {
|
type Browser struct {
|
||||||
customAgent string
|
customAgent string
|
||||||
tempDir string
|
tempDir string
|
||||||
previousPIDs map[int32]struct{} // track already running PIDs
|
engine *rod.Browser
|
||||||
engine *rod.Browser
|
options *types.Options
|
||||||
options *types.Options
|
launcher *launcher.Launcher
|
||||||
// use getHTTPClient to get the http client
|
// use getHTTPClient to get the http client
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
httpClientOnce *sync.Once
|
httpClientOnce *sync.Once
|
||||||
@ -36,7 +35,6 @@ func New(options *types.Options) (*Browser, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not create temporary directory")
|
return nil, errors.Wrap(err, "could not create temporary directory")
|
||||||
}
|
}
|
||||||
previousPIDs := processutil.FindProcesses(processutil.IsChromeProcess)
|
|
||||||
|
|
||||||
chromeLauncher := launcher.New().
|
chromeLauncher := launcher.New().
|
||||||
Leakless(false).
|
Leakless(false).
|
||||||
@ -110,8 +108,8 @@ func New(options *types.Options) (*Browser, error) {
|
|||||||
engine: browser,
|
engine: browser,
|
||||||
options: options,
|
options: options,
|
||||||
httpClientOnce: &sync.Once{},
|
httpClientOnce: &sync.Once{},
|
||||||
|
launcher: chromeLauncher,
|
||||||
}
|
}
|
||||||
engine.previousPIDs = previousPIDs
|
|
||||||
return engine, nil
|
return engine, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +141,6 @@ func (b *Browser) getHTTPClient() (*http.Client, error) {
|
|||||||
// Close closes the browser engine
|
// Close closes the browser engine
|
||||||
func (b *Browser) Close() {
|
func (b *Browser) Close() {
|
||||||
b.engine.Close()
|
b.engine.Close()
|
||||||
|
b.launcher.Kill()
|
||||||
os.RemoveAll(b.tempDir)
|
os.RemoveAll(b.tempDir)
|
||||||
processutil.CloseProcesses(processutil.IsChromeProcess, b.previousPIDs)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user