diff --git a/README.md b/README.md index 7970387..14f1093 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ RendererContext values: - `BrowserExecPath`: Manually set chrome / chromium browser's executable path - Type: String - Default: Empty string (Auto detect) +- `NoSandbox`: Set to disable using sandbox for isolating browser process (usually use in docker container or AWS lambda) + - Type: bool + - Default: false ### Example See usage example at [examples](examples/render/main.go) @@ -54,6 +57,8 @@ Usage of ./render: how to determine loading idle and return, valid input: networkIdle, InteractiveTime (default "networkIdle") -imageLoad indicate if load image when rendering + -sandbox + indicate if using sandbox for isolating browser process (default true) -skipFrameCount int skip first n frames with same id as init frame, only valid with idleType=networkIdle -timeout int @@ -92,6 +97,9 @@ PdfContext values: - `BrowserExecPath`: Manually set chrome / chromium browser's executable path - Type: String - Default: Empty string (Auto detect) +- `NoSandbox`: Set to disable using sandbox for isolating browser process (usually use in docker container or AWS lambda) + - Type: bool + - Default: false ### Example See usage example at [examples](examples/pdf/main.go) @@ -124,6 +132,8 @@ Usage of ./pdf.out: paper height in centimeter -paperWidth float paper width in centimeter + -sandbox + indicate if using sandbox for isolating browser process (default true) ``` diff --git a/context.go b/context.go index 069f031..e221a29 100644 --- a/context.go +++ b/context.go @@ -27,6 +27,7 @@ type RendererContext struct { IdleType string SkipFrameCount int BrowserExecPath string + NoSandbox bool } // WithRendererContext add RendererContext with rendererKey to context and return @@ -60,6 +61,7 @@ type PdfContext struct { MarginRightCm float64 IdleType string BrowserExecPath string + NoSandbox bool } // WithPdfContext add PdfContext with pdfKey to context and return diff --git a/examples/pdf/main.go b/examples/pdf/main.go index 11d9970..37f471f 100644 --- a/examples/pdf/main.go +++ b/examples/pdf/main.go @@ -22,6 +22,7 @@ func main() { idleType := flag.String("idleType", "networkIdle", "how to determine loading idle and return, valid input: networkIdle, InteractiveTime") browserExecPath := flag.String("browserPath", "", "manually set browser executable path") + sandbox := flag.Bool("sandbox", true, "indicate if using sandbox for isolating browser process") flag.Parse() if *paperWidth < 0 || *paperHeight < 0 { @@ -53,6 +54,7 @@ func main() { MarginRightCm: *marginRight, IdleType: *idleType, BrowserExecPath: *browserExecPath, + NoSandbox: !*sandbox, } ctx := context.Background() diff --git a/examples/render/main.go b/examples/render/main.go index 281f7b9..f613c12 100644 --- a/examples/render/main.go +++ b/examples/render/main.go @@ -21,6 +21,7 @@ func main() { skipFrameCount := flag.Int("skipFrameCount", 0, "skip first n frames with same id as init frame, only valid with idleType=networkIdle") browserExecPath := flag.String("browserPath", "", "manually set browser executable path") + sandbox := flag.Bool("sandbox", true, "indicate if using sandbox for isolating browser process") flag.Parse() if *browserWidth <= 0 || *browserHeight <= 0 { @@ -50,6 +51,7 @@ func main() { IdleType: *idleType, SkipFrameCount: *skipFrameCount, BrowserExecPath: *browserExecPath, + NoSandbox: !*sandbox, } ctx := context.Background() diff --git a/renderer.go b/renderer.go index 4846627..ba5afcc 100644 --- a/renderer.go +++ b/renderer.go @@ -47,6 +47,11 @@ func RenderPdf(ctx context.Context, urlStr string) ([]byte, error) { opts = append(opts, chromedp.ExecPath(pdfContext.BrowserExecPath)) } + if pdfContext.NoSandbox { + fmt.Println("Set NoSandbox config") + opts = append(opts, chromedp.NoSandbox) + } + start := time.Now() ctx, cancel := chromedp.NewExecAllocator(ctx, opts...) defer cancel() @@ -110,6 +115,11 @@ func RenderPage(ctx context.Context, urlStr string) ([]byte, error) { if rendererContext.BrowserExecPath != "" { opts = append(opts, chromedp.ExecPath(rendererContext.BrowserExecPath)) } + + if rendererContext.NoSandbox { + fmt.Println("Set NoSandbox config") + opts = append(opts, chromedp.NoSandbox) + } // fmt.Printf("Rendering: %s\n", urlStr) start := time.Now()