From 9ceca85a37f2d83a13ee6c55d9ff0b8410cf1102 Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Wed, 13 Jan 2021 17:10:20 +0200 Subject: [PATCH 1/7] Expose PID from the Browser --- browser.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/browser.go b/browser.go index 42b6818c..1bb73c80 100644 --- a/browser.go +++ b/browser.go @@ -310,6 +310,11 @@ func (b *Browser) run(ctx context.Context) { } } +// Pid returning browser PID +func (b *Browser) Pid() int { + return b.process.Pid +} + // BrowserOption is a browser option. type BrowserOption = func(*Browser) From 96623c25131fc2790db7495dd9fab95082634ea8 Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Wed, 13 Jan 2021 17:19:47 +0200 Subject: [PATCH 2/7] Update browser.go Co-authored-by: Dmytro Vovk --- browser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser.go b/browser.go index 1bb73c80..003ea499 100644 --- a/browser.go +++ b/browser.go @@ -310,7 +310,7 @@ func (b *Browser) run(ctx context.Context) { } } -// Pid returning browser PID +// Pid returns the browser process ID func (b *Browser) Pid() int { return b.process.Pid } From 4ac531d76c762884ff9d6b1cf44329e738afb396 Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Wed, 13 Jan 2021 17:46:49 +0200 Subject: [PATCH 3/7] Review change --- browser.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser.go b/browser.go index 003ea499..38bd09a3 100644 --- a/browser.go +++ b/browser.go @@ -310,8 +310,8 @@ func (b *Browser) run(ctx context.Context) { } } -// Pid returns the browser process ID -func (b *Browser) Pid() int { +// PID returns the browser process ID +func (b *Browser) PID() int { return b.process.Pid } From 78c5f784c9cd86b3fc8acb27f0bbd63d05d2b3fd Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Thu, 29 Apr 2021 20:36:41 +0300 Subject: [PATCH 4/7] Review changes --- browser.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/browser.go b/browser.go index 38bd09a3..cae48c14 100644 --- a/browser.go +++ b/browser.go @@ -310,9 +310,13 @@ func (b *Browser) run(ctx context.Context) { } } -// PID returns the browser process ID -func (b *Browser) PID() int { - return b.process.Pid +// Process returns the Chrome process object +// Example: +// if process := chromedp.FromContext(ctx).Browser.Process(); process != nil { +// fmt.Printf("Chrome PID: %v", process.Pid) +// } +func (b *Browser) Process() *os.Process { + return b.process } // BrowserOption is a browser option. From 430cd6e29c6b0be66ae43f11668a8c463d49564d Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Fri, 30 Apr 2021 10:33:28 +0300 Subject: [PATCH 5/7] Review changes --- browser.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/browser.go b/browser.go index cae48c14..f7f6b063 100644 --- a/browser.go +++ b/browser.go @@ -119,6 +119,18 @@ func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Bro return b, nil } +// Process returns the process object of the browser. +// It could be nil when the browser is allocated with RemoteAllocator. +// It can be used to control the memory consumed by the browser process. +// +// Example: +// if process := chromedp.FromContext(ctx).Browser.Process(); process != nil { +// fmt.Printf("Browser PID: %v", process.Pid) +// } +func (b *Browser) Process() *os.Process { + return b.process +} + func (b *Browser) newExecutorForTarget(ctx context.Context, targetID target.ID, sessionID target.SessionID) (*Target, error) { if targetID == "" { return nil, errors.New("empty target ID") @@ -310,15 +322,6 @@ func (b *Browser) run(ctx context.Context) { } } -// Process returns the Chrome process object -// Example: -// if process := chromedp.FromContext(ctx).Browser.Process(); process != nil { -// fmt.Printf("Chrome PID: %v", process.Pid) -// } -func (b *Browser) Process() *os.Process { - return b.process -} - // BrowserOption is a browser option. type BrowserOption = func(*Browser) From 7529aee43e6d4135dae01033dbad6469f38a4584 Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Fri, 30 Apr 2021 11:10:57 +0300 Subject: [PATCH 6/7] Review changes --- browser.go | 1 + 1 file changed, 1 insertion(+) diff --git a/browser.go b/browser.go index f7f6b063..3bea8f01 100644 --- a/browser.go +++ b/browser.go @@ -120,6 +120,7 @@ func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Bro } // Process returns the process object of the browser. +// // It could be nil when the browser is allocated with RemoteAllocator. // It can be used to control the memory consumed by the browser process. // From 0564670a4ec42b664d5a326656ff095c27076c8a Mon Sep 17 00:00:00 2001 From: Sergey Mudrik Date: Fri, 30 Apr 2021 11:47:50 +0300 Subject: [PATCH 7/7] Review changes --- browser.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/browser.go b/browser.go index 3bea8f01..17bb083f 100644 --- a/browser.go +++ b/browser.go @@ -122,7 +122,8 @@ func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Bro // Process returns the process object of the browser. // // It could be nil when the browser is allocated with RemoteAllocator. -// It can be used to control the memory consumed by the browser process. +// It could be useful for a monitoring system to collect process metrics of the browser process. +// (see https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#NewProcessCollector for an example) // // Example: // if process := chromedp.FromContext(ctx).Browser.Process(); process != nil {