Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose os.Process from the Browser #737

Merged
merged 7 commits into from Apr 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions browser.go
Expand Up @@ -119,6 +119,20 @@ 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.
ZekeLu marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
// 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")
Expand Down