forked from Davincible/chromedp-undetected
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chrome_unix.go
40 lines (31 loc) · 986 Bytes
/
chrome_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//go:build linux
// Package chromedpundetected provides a chromedp context with an undetected
// Chrome browser.
package chromedpundetected
import (
"os"
"os/exec"
"syscall"
"github.com/chromedp/chromedp"
)
func headlessOpts() (opts []chromedp.ExecAllocatorOption, cleanup func() error, err error) {
// Create virtual display
frameBuffer, err := newFrameBuffer("1920x1080x24")
if err != nil {
return nil, nil, err
}
opt := chromedp.ModifyCmdFunc(func(cmd *exec.Cmd) {
cmd.Env = append(cmd.Env, "DISPLAY=:"+frameBuffer.Display)
cmd.Env = append(cmd.Env, "XAUTHORITY="+frameBuffer.AuthPath)
// Do nothing on AWS Lambda
if _, ok := os.LookupEnv("LAMBDA_TASK_ROOT"); ok {
return
}
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = new(syscall.SysProcAttr)
}
// When the parent process dies (Go), kill all the chid processes as well.
cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
})
return []chromedp.ExecAllocatorOption{opt}, frameBuffer.Stop, nil
}