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 5 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
12 changes: 12 additions & 0 deletions browser.go
Expand Up @@ -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.
ZekeLu marked this conversation as resolved.
Show resolved Hide resolved
// It can be used to control the memory consumed by the browser process.
ZekeLu marked this conversation as resolved.
Show resolved Hide resolved
//
// 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