package chromium import ( "context" "errors" "fmt" "io/ioutil" "os" "regexp" "strings" "sync" "time" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/fetch" "github.com/chromedp/cdproto/network" "github.com/chromedp/cdproto/page" "github.com/chromedp/cdproto/runtime" "github.com/chromedp/chromedp" "github.com/gotenberg/gotenberg/v7/pkg/gotenberg" "github.com/gotenberg/gotenberg/v7/pkg/modules/api" flag "github.com/spf13/pflag" "go.uber.org/zap" "golang.org/x/sync/errgroup" ) func init() { gotenberg.MustRegisterModule(Chromium{}) } var ( // ErrURLNotAuthorized happens if a URL is not acceptable according to the // allowed/denied lists. ErrURLNotAuthorized = errors.New("URL not authorized") // ErrInvalidEmulatedMediaType happens if the emulated media type is not // "screen" nor "print". Empty value are allowed though. ErrInvalidEmulatedMediaType = errors.New("invalid emulated media type") // ErrInvalidEvaluationExpression happens if an evaluation expression // returns an exception or undefined. ErrInvalidEvaluationExpression = errors.New("invalid evaluation expression") // ErrInvalidPrinterSettings happens if the Options have one or more // aberrant values. ErrInvalidPrinterSettings = errors.New("invalid printer settings") // ErrPageRangesSyntaxError happens if the Options have an invalid page // ranges. ErrPageRangesSyntaxError = errors.New("page ranges syntax error") // ErrRpccMessageTooLarge happens when the messages received by // ChromeDevTools are larger than 100 MB. ErrRpccMessageTooLarge = errors.New("rpcc message too large") // ErrConsoleExceptions happens when there are exceptions in the Chromium // console. It also happens only if the Options.FailOnConsoleExceptions is // set to true. ErrConsoleExceptions = errors.New("console exceptions") ) // Chromium is a module which provides both an API and routes for converting // HTML document to PDF. type Chromium struct { binPath string engine gotenberg.PDFEngine userAgent string incognito bool ignoreCertificateErrors bool disableWebSecurity bool allowFileAccessFromFiles bool proxyServer string allowList *regexp.Regexp denyList *regexp.Regexp disableJavaScript bool disableRoutes bool } // LinkTag represents an HTML element. type LinkTag struct { // Href is the "href" attribute of the HTML element. // Required. Href string `json:"href"` } // ScriptTag represents an HTML