diff --git a/cdp/cdp.go b/cdp/cdp.go index 9f74962..bfb787c 100644 --- a/cdp/cdp.go +++ b/cdp/cdp.go @@ -98,6 +98,7 @@ const ( CommandPageSetControlNavigations MethodType = "Page.setControlNavigations" CommandPageProcessNavigation MethodType = "Page.processNavigation" CommandPageGetLayoutMetrics MethodType = "Page.getLayoutMetrics" + CommandPageCreateIsolatedWorld MethodType = "Page.createIsolatedWorld" EventOverlayNodeHighlightRequested MethodType = "Overlay.nodeHighlightRequested" EventOverlayInspectNodeRequested MethodType = "Overlay.inspectNodeRequested" CommandOverlayEnable MethodType = "Overlay.enable" @@ -576,6 +577,8 @@ func (t *MethodType) UnmarshalEasyJSON(in *jlexer.Lexer) { *t = CommandPageProcessNavigation case CommandPageGetLayoutMetrics: *t = CommandPageGetLayoutMetrics + case CommandPageCreateIsolatedWorld: + *t = CommandPageCreateIsolatedWorld case EventOverlayNodeHighlightRequested: *t = EventOverlayNodeHighlightRequested case EventOverlayInspectNodeRequested: diff --git a/cdp/cdputil/cdputil.go b/cdp/cdputil/cdputil.go index 9902c16..e8e2678 100644 --- a/cdp/cdputil/cdputil.go +++ b/cdp/cdputil/cdputil.go @@ -144,6 +144,9 @@ func UnmarshalMessage(msg *cdp.Message) (interface{}, error) { case cdp.CommandPageGetLayoutMetrics: v = new(page.GetLayoutMetricsReturns) + case cdp.CommandPageCreateIsolatedWorld: + return emptyVal, nil + case cdp.EventPageDomContentEventFired: v = new(page.EventDomContentEventFired) diff --git a/cdp/page/easyjson.go b/cdp/page/easyjson.go index 4f1c04f..c659363 100644 --- a/cdp/page/easyjson.go +++ b/cdp/page/easyjson.go @@ -1366,6 +1366,28 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage16(in *jlexer.Lexer, out * continue } switch key { + case "landscape": + out.Landscape = bool(in.Bool()) + case "displayHeaderFooter": + out.DisplayHeaderFooter = bool(in.Bool()) + case "printBackground": + out.PrintBackground = bool(in.Bool()) + case "scale": + out.Scale = float64(in.Float64()) + case "paperWidth": + out.PaperWidth = float64(in.Float64()) + case "paperHeight": + out.PaperHeight = float64(in.Float64()) + case "marginTop": + out.MarginTop = float64(in.Float64()) + case "marginBottom": + out.MarginBottom = float64(in.Float64()) + case "marginLeft": + out.MarginLeft = float64(in.Float64()) + case "marginRight": + out.MarginRight = float64(in.Float64()) + case "pageRanges": + out.PageRanges = string(in.String()) default: in.SkipRecursive() } @@ -1380,6 +1402,94 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage16(out *jwriter.Writer, in out.RawByte('{') first := true _ = first + if in.Landscape { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"landscape\":") + out.Bool(bool(in.Landscape)) + } + if in.DisplayHeaderFooter { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"displayHeaderFooter\":") + out.Bool(bool(in.DisplayHeaderFooter)) + } + if in.PrintBackground { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"printBackground\":") + out.Bool(bool(in.PrintBackground)) + } + if in.Scale != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"scale\":") + out.Float64(float64(in.Scale)) + } + if in.PaperWidth != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"paperWidth\":") + out.Float64(float64(in.PaperWidth)) + } + if in.PaperHeight != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"paperHeight\":") + out.Float64(float64(in.PaperHeight)) + } + if in.MarginTop != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"marginTop\":") + out.Float64(float64(in.MarginTop)) + } + if in.MarginBottom != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"marginBottom\":") + out.Float64(float64(in.MarginBottom)) + } + if in.MarginLeft != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"marginLeft\":") + out.Float64(float64(in.MarginLeft)) + } + if in.MarginRight != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"marginRight\":") + out.Float64(float64(in.MarginRight)) + } + if in.PageRanges != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"pageRanges\":") + out.String(string(in.PageRanges)) + } out.RawByte('}') } @@ -4441,7 +4551,94 @@ func (v *DisableParams) UnmarshalJSON(data []byte) error { func (v *DisableParams) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage53(l, v) } -func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(in *jlexer.Lexer, out *CaptureScreenshotReturns) { +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(in *jlexer.Lexer, out *CreateIsolatedWorldParams) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeString() + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "frameId": + (out.FrameID).UnmarshalEasyJSON(in) + case "worldName": + out.WorldName = string(in.String()) + case "grantUniveralAccess": + out.GrantUniveralAccess = bool(in.Bool()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(out *jwriter.Writer, in CreateIsolatedWorldParams) { + out.RawByte('{') + first := true + _ = first + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"frameId\":") + out.String(string(in.FrameID)) + if in.WorldName != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"worldName\":") + out.String(string(in.WorldName)) + } + if in.GrantUniveralAccess { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"grantUniveralAccess\":") + out.Bool(bool(in.GrantUniveralAccess)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v CreateIsolatedWorldParams) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v CreateIsolatedWorldParams) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *CreateIsolatedWorldParams) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *CreateIsolatedWorldParams) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(in *jlexer.Lexer, out *CaptureScreenshotReturns) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -4472,7 +4669,7 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(in *jlexer.Lexer, out * in.Consumed() } } -func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(out *jwriter.Writer, in CaptureScreenshotReturns) { +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(out *jwriter.Writer, in CaptureScreenshotReturns) { out.RawByte('{') first := true _ = first @@ -4490,27 +4687,27 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v CaptureScreenshotReturns) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(&w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CaptureScreenshotReturns) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage54(w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CaptureScreenshotReturns) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(&r, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CaptureScreenshotReturns) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage54(l, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(l, v) } -func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(in *jlexer.Lexer, out *CaptureScreenshotParams) { +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(in *jlexer.Lexer, out *CaptureScreenshotParams) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -4545,7 +4742,7 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(in *jlexer.Lexer, out * in.Consumed() } } -func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(out *jwriter.Writer, in CaptureScreenshotParams) { +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(out *jwriter.Writer, in CaptureScreenshotParams) { out.RawByte('{') first := true _ = first @@ -4579,27 +4776,27 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v CaptureScreenshotParams) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(&w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CaptureScreenshotParams) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage55(w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CaptureScreenshotParams) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(&r, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CaptureScreenshotParams) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage55(l, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(l, v) } -func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(in *jlexer.Lexer, out *AppManifestError) { +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(in *jlexer.Lexer, out *AppManifestError) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -4636,7 +4833,7 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(in *jlexer.Lexer, out * in.Consumed() } } -func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(out *jwriter.Writer, in AppManifestError) { +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(out *jwriter.Writer, in AppManifestError) { out.RawByte('{') first := true _ = first @@ -4678,27 +4875,27 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v AppManifestError) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(&w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AppManifestError) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage56(w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AppManifestError) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(&r, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AppManifestError) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage56(l, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(l, v) } -func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(in *jlexer.Lexer, out *AddScriptToEvaluateOnLoadReturns) { +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(in *jlexer.Lexer, out *AddScriptToEvaluateOnLoadReturns) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -4729,7 +4926,7 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(in *jlexer.Lexer, out * in.Consumed() } } -func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(out *jwriter.Writer, in AddScriptToEvaluateOnLoadReturns) { +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(out *jwriter.Writer, in AddScriptToEvaluateOnLoadReturns) { out.RawByte('{') first := true _ = first @@ -4747,27 +4944,27 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v AddScriptToEvaluateOnLoadReturns) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(&w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AddScriptToEvaluateOnLoadReturns) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage57(w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AddScriptToEvaluateOnLoadReturns) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(&r, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AddScriptToEvaluateOnLoadReturns) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage57(l, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(l, v) } -func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(in *jlexer.Lexer, out *AddScriptToEvaluateOnLoadParams) { +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage59(in *jlexer.Lexer, out *AddScriptToEvaluateOnLoadParams) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -4798,7 +4995,7 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(in *jlexer.Lexer, out * in.Consumed() } } -func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(out *jwriter.Writer, in AddScriptToEvaluateOnLoadParams) { +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage59(out *jwriter.Writer, in AddScriptToEvaluateOnLoadParams) { out.RawByte('{') first := true _ = first @@ -4814,23 +5011,23 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v AddScriptToEvaluateOnLoadParams) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(&w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage59(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AddScriptToEvaluateOnLoadParams) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage58(w, v) + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpPage59(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AddScriptToEvaluateOnLoadParams) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(&r, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage59(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AddScriptToEvaluateOnLoadParams) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage58(l, v) + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpPage59(l, v) } diff --git a/cdp/page/page.go b/cdp/page/page.go index c30208d..f9fe1a2 100644 --- a/cdp/page/page.go +++ b/cdp/page/page.go @@ -491,14 +491,95 @@ func (p *CaptureScreenshotParams) Do(ctxt context.Context, h cdp.Handler) (data return dec, nil } -// PrintToPDFParams print page as pdf. -type PrintToPDFParams struct{} +// PrintToPDFParams print page as PDF. +type PrintToPDFParams struct { + Landscape bool `json:"landscape,omitempty"` // Paper orientation. Defaults to false. + DisplayHeaderFooter bool `json:"displayHeaderFooter,omitempty"` // Display header and footer. Defaults to false. + PrintBackground bool `json:"printBackground,omitempty"` // Print background graphics. Defaults to false. + Scale float64 `json:"scale,omitempty"` // Scale of the webpage rendering. Defaults to 1. + PaperWidth float64 `json:"paperWidth,omitempty"` // Paper width in inches. Defaults to 8.5 inches. + PaperHeight float64 `json:"paperHeight,omitempty"` // Paper height in inches. Defaults to 11 inches. + MarginTop float64 `json:"marginTop,omitempty"` // Top margin in inches. Defaults to 1cm (~0.4 inches). + MarginBottom float64 `json:"marginBottom,omitempty"` // Bottom margin in inches. Defaults to 1cm (~0.4 inches). + MarginLeft float64 `json:"marginLeft,omitempty"` // Left margin in inches. Defaults to 1cm (~0.4 inches). + MarginRight float64 `json:"marginRight,omitempty"` // Right margin in inches. Defaults to 1cm (~0.4 inches). + PageRanges string `json:"pageRanges,omitempty"` // Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. +} -// PrintToPDF print page as pdf. +// PrintToPDF print page as PDF. +// +// parameters: func PrintToPDF() *PrintToPDFParams { return &PrintToPDFParams{} } +// WithLandscape paper orientation. Defaults to false. +func (p PrintToPDFParams) WithLandscape(landscape bool) *PrintToPDFParams { + p.Landscape = landscape + return &p +} + +// WithDisplayHeaderFooter display header and footer. Defaults to false. +func (p PrintToPDFParams) WithDisplayHeaderFooter(displayHeaderFooter bool) *PrintToPDFParams { + p.DisplayHeaderFooter = displayHeaderFooter + return &p +} + +// WithPrintBackground print background graphics. Defaults to false. +func (p PrintToPDFParams) WithPrintBackground(printBackground bool) *PrintToPDFParams { + p.PrintBackground = printBackground + return &p +} + +// WithScale scale of the webpage rendering. Defaults to 1. +func (p PrintToPDFParams) WithScale(scale float64) *PrintToPDFParams { + p.Scale = scale + return &p +} + +// WithPaperWidth paper width in inches. Defaults to 8.5 inches. +func (p PrintToPDFParams) WithPaperWidth(paperWidth float64) *PrintToPDFParams { + p.PaperWidth = paperWidth + return &p +} + +// WithPaperHeight paper height in inches. Defaults to 11 inches. +func (p PrintToPDFParams) WithPaperHeight(paperHeight float64) *PrintToPDFParams { + p.PaperHeight = paperHeight + return &p +} + +// WithMarginTop top margin in inches. Defaults to 1cm (~0.4 inches). +func (p PrintToPDFParams) WithMarginTop(marginTop float64) *PrintToPDFParams { + p.MarginTop = marginTop + return &p +} + +// WithMarginBottom bottom margin in inches. Defaults to 1cm (~0.4 inches). +func (p PrintToPDFParams) WithMarginBottom(marginBottom float64) *PrintToPDFParams { + p.MarginBottom = marginBottom + return &p +} + +// WithMarginLeft left margin in inches. Defaults to 1cm (~0.4 inches). +func (p PrintToPDFParams) WithMarginLeft(marginLeft float64) *PrintToPDFParams { + p.MarginLeft = marginLeft + return &p +} + +// WithMarginRight right margin in inches. Defaults to 1cm (~0.4 inches). +func (p PrintToPDFParams) WithMarginRight(marginRight float64) *PrintToPDFParams { + p.MarginRight = marginRight + return &p +} + +// WithPageRanges paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to +// the empty string, which means print all pages. +func (p PrintToPDFParams) WithPageRanges(pageRanges string) *PrintToPDFParams { + p.PageRanges = pageRanges + return &p +} + // PrintToPDFReturns return values. type PrintToPDFReturns struct { Data string `json:"data,omitempty"` // Base64-encoded pdf data. @@ -512,7 +593,7 @@ type PrintToPDFReturns struct { func (p *PrintToPDFParams) Do(ctxt context.Context, h cdp.Handler) (data []byte, err error) { // execute var res PrintToPDFReturns - err = h.Execute(ctxt, cdp.CommandPagePrintToPDF, nil, &res) + err = h.Execute(ctxt, cdp.CommandPagePrintToPDF, p, &res) if err != nil { return nil, err } @@ -778,3 +859,39 @@ func (p *GetLayoutMetricsParams) Do(ctxt context.Context, h cdp.Handler) (layout return res.LayoutViewport, res.VisualViewport, res.ContentSize, nil } + +// CreateIsolatedWorldParams creates an isolated world for the given frame. +type CreateIsolatedWorldParams struct { + FrameID cdp.FrameID `json:"frameId"` // Id of the frame in which the isolated world should be created. + WorldName string `json:"worldName,omitempty"` // An optional name which is reported in the Execution Context. + GrantUniveralAccess bool `json:"grantUniveralAccess,omitempty"` // Whether or not universal access should be granted to the isolated world. This is a powerful option, use with caution. +} + +// CreateIsolatedWorld creates an isolated world for the given frame. +// +// parameters: +// frameID - Id of the frame in which the isolated world should be created. +func CreateIsolatedWorld(frameID cdp.FrameID) *CreateIsolatedWorldParams { + return &CreateIsolatedWorldParams{ + FrameID: frameID, + } +} + +// WithWorldName an optional name which is reported in the Execution Context. +func (p CreateIsolatedWorldParams) WithWorldName(worldName string) *CreateIsolatedWorldParams { + p.WorldName = worldName + return &p +} + +// WithGrantUniveralAccess whether or not universal access should be granted +// to the isolated world. This is a powerful option, use with caution. +func (p CreateIsolatedWorldParams) WithGrantUniveralAccess(grantUniveralAccess bool) *CreateIsolatedWorldParams { + p.GrantUniveralAccess = grantUniveralAccess + return &p +} + +// Do executes Page.createIsolatedWorld against the provided context and +// target handler. +func (p *CreateIsolatedWorldParams) Do(ctxt context.Context, h cdp.Handler) (err error) { + return h.Execute(ctxt, cdp.CommandPageCreateIsolatedWorld, p, nil) +} diff --git a/cmd/chromedp-gen/protocol.json b/cmd/chromedp-gen/protocol.json index 50ad530..beb1782 100644 --- a/cmd/chromedp-gen/protocol.json +++ b/cmd/chromedp-gen/protocol.json @@ -922,7 +922,75 @@ }, { "name": "printToPDF", - "description": "Print page as pdf.", + "description": "Print page as PDF.", + "parameters": [ + { + "name": "landscape", + "type": "boolean", + "optional": true, + "description": "Paper orientation. Defaults to false." + }, + { + "name": "displayHeaderFooter", + "type": "boolean", + "optional": true, + "description": "Display header and footer. Defaults to false." + }, + { + "name": "printBackground", + "type": "boolean", + "optional": true, + "description": "Print background graphics. Defaults to false." + }, + { + "name": "scale", + "type": "number", + "optional": true, + "description": "Scale of the webpage rendering. Defaults to 1." + }, + { + "name": "paperWidth", + "type": "number", + "optional": true, + "description": "Paper width in inches. Defaults to 8.5 inches." + }, + { + "name": "paperHeight", + "type": "number", + "optional": true, + "description": "Paper height in inches. Defaults to 11 inches." + }, + { + "name": "marginTop", + "type": "number", + "optional": true, + "description": "Top margin in inches. Defaults to 1cm (~0.4 inches)." + }, + { + "name": "marginBottom", + "type": "number", + "optional": true, + "description": "Bottom margin in inches. Defaults to 1cm (~0.4 inches)." + }, + { + "name": "marginLeft", + "type": "number", + "optional": true, + "description": "Left margin in inches. Defaults to 1cm (~0.4 inches)." + }, + { + "name": "marginRight", + "type": "number", + "optional": true, + "description": "Right margin in inches. Defaults to 1cm (~0.4 inches)." + }, + { + "name": "pageRanges", + "type": "string", + "optional": true, + "description": "Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages." + } + ], "returns": [ { "name": "data", @@ -1082,6 +1150,30 @@ "description": "Size of scrollable area." } ] + }, + { + "name": "createIsolatedWorld", + "description": "Creates an isolated world for the given frame.", + "experimental": true, + "parameters": [ + { + "name": "frameId", + "$ref": "FrameId", + "description": "Id of the frame in which the isolated world should be created." + }, + { + "name": "worldName", + "type": "string", + "optional": true, + "description": "An optional name which is reported in the Execution Context." + }, + { + "name": "grantUniveralAccess", + "type": "boolean", + "optional": true, + "description": "Whether or not universal access should be granted to the isolated world. This is a powerful option, use with caution." + } + ] } ], "events": [