From 19a615bbfa3d92cb597128e9924dd00ab80b177c Mon Sep 17 00:00:00 2001 From: Yad Smood Date: Thu, 7 Apr 2022 20:33:47 +0800 Subject: [PATCH] use pointer for optional number that default value is not 0 --- element.go | 4 +- examples_test.go | 7 +- input.go | 9 +- lib/devices/device.go | 3 +- .../compare-chromedp/screenshot/main.go | 3 +- lib/proto/a_interface_test.go | 20 ----- lib/proto/a_patch.go | 87 ------------------- lib/proto/accessibility.go | 2 +- lib/proto/audits.go | 4 +- lib/proto/browser.go | 8 +- lib/proto/cache_storage.go | 4 +- lib/proto/console.go | 4 +- lib/proto/css.go | 2 +- lib/proto/debugger.go | 16 ++-- lib/proto/dom.go | 12 +-- lib/proto/dom_debugger.go | 2 +- lib/proto/dom_snapshot.go | 20 ++--- lib/proto/emulation.go | 22 ++--- lib/proto/fetch.go | 4 +- lib/proto/generate/main.go | 12 ++- lib/proto/generate/patch.go | 7 ++ lib/proto/headless_experimental.go | 6 +- lib/proto/heap_profiler.go | 2 +- lib/proto/indexed_db.go | 4 +- lib/proto/input.go | 44 +++++----- lib/proto/io.go | 4 +- lib/proto/layer_tree.go | 16 ++-- lib/proto/log.go | 2 +- lib/proto/memory.go | 2 +- lib/proto/network.go | 26 +++--- lib/proto/page.go | 48 +++++----- lib/proto/performance_timeline.go | 2 +- lib/proto/profiler.go | 2 +- lib/proto/service_worker.go | 4 +- lib/proto/storage.go | 2 +- lib/proto/system_info.go | 4 +- lib/proto/target.go | 4 +- lib/proto/tracing.go | 8 +- lib/proto/web_audio.go | 12 +-- must.go | 8 +- page_test.go | 8 +- utils.go | 2 +- 42 files changed, 188 insertions(+), 274 deletions(-) diff --git a/element.go b/element.go index f2b004e9..6610cc97 100644 --- a/element.go +++ b/element.go @@ -391,7 +391,7 @@ func (el *Element) SetFiles(paths []string) error { // is fired all NodeID on the page will be reassigned to another value) // we don't recommend using the NodeID, instead, use the BackendNodeID to identify the element. func (el *Element) Describe(depth int, pierce bool) (*proto.DOMNode, error) { - val, err := proto.DOMDescribeNode{ObjectID: el.id(), Depth: depth, Pierce: pierce}.Call(el) + val, err := proto.DOMDescribeNode{ObjectID: el.id(), Depth: gson.Int(depth), Pierce: pierce}.Call(el) if err != nil { return nil, err } @@ -651,7 +651,7 @@ func (el *Element) Screenshot(format proto.PageCaptureScreenshotFormat, quality } opts := &proto.PageCaptureScreenshot{ - Quality: quality, + Quality: gson.Int(quality), Format: format, } diff --git a/examples_test.go b/examples_test.go index 8a6a85d5..86aad331 100644 --- a/examples_test.go +++ b/examples_test.go @@ -16,6 +16,7 @@ import ( "github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/proto" "github.com/go-rod/rod/lib/utils" + "github.com/ysmood/gson" ) // This example opens https://github.com/, searches for "git", @@ -213,7 +214,7 @@ func Example_page_screenshot() { // customization version img, _ := page.Screenshot(true, &proto.PageCaptureScreenshot{ Format: proto.PageCaptureScreenshotFormatJpeg, - Quality: 90, + Quality: gson.Int(90), Clip: &proto.PageViewport{ X: 0, Y: 0, @@ -234,8 +235,8 @@ func Example_page_pdf() { // customized version pdf, _ := page.PDF(&proto.PagePrintToPDF{ - PaperWidth: 8.5, - PaperHeight: 11, + PaperWidth: gson.Num(8.5), + PaperHeight: gson.Num(11), PageRanges: "1-3", }) _ = utils.OutputFile("my.pdf", pdf) diff --git a/input.go b/input.go index 44139646..237bd664 100644 --- a/input.go +++ b/input.go @@ -6,6 +6,7 @@ import ( "github.com/go-rod/rod/lib/input" "github.com/go-rod/rod/lib/proto" + "github.com/ysmood/gson" ) // Keyboard represents the keyboard on a page, it's always related the main frame @@ -134,7 +135,7 @@ func (m *Mouse) Move(x, y float64, steps int) error { X: toX, Y: toY, Button: button, - Buttons: buttons, + Buttons: gson.Int(buttons), Modifiers: m.page.Keyboard.getModifiers(), }.Call(m.page) if err != nil { @@ -179,7 +180,7 @@ func (m *Mouse) Scroll(offsetX, offsetY float64, steps int) error { X: m.x, Y: m.y, Button: button, - Buttons: buttons, + Buttons: gson.Int(buttons), Modifiers: m.page.Keyboard.getModifiers(), DeltaX: stepX, DeltaY: stepY, @@ -204,7 +205,7 @@ func (m *Mouse) Down(button proto.InputMouseButton, clicks int) error { err := proto.InputDispatchMouseEvent{ Type: proto.InputDispatchMouseEventTypeMousePressed, Button: button, - Buttons: buttons, + Buttons: gson.Int(buttons), ClickCount: clicks, Modifiers: m.page.Keyboard.getModifiers(), X: m.x, @@ -235,7 +236,7 @@ func (m *Mouse) Up(button proto.InputMouseButton, clicks int) error { err := proto.InputDispatchMouseEvent{ Type: proto.InputDispatchMouseEventTypeMouseReleased, Button: button, - Buttons: buttons, + Buttons: gson.Int(buttons), ClickCount: clicks, Modifiers: m.page.Keyboard.getModifiers(), X: m.x, diff --git a/lib/devices/device.go b/lib/devices/device.go index 31fa6483..165751f1 100644 --- a/lib/devices/device.go +++ b/lib/devices/device.go @@ -2,6 +2,7 @@ package devices import ( "github.com/go-rod/rod/lib/proto" + "github.com/ysmood/gson" ) // Device represents a emulated device. @@ -77,7 +78,7 @@ func (device Device) TouchEmulation() *proto.EmulationSetTouchEmulationEnabled { return &proto.EmulationSetTouchEmulationEnabled{ Enabled: has(device.Capabilities, "touch"), - MaxTouchPoints: 5, + MaxTouchPoints: gson.Int(5), } } diff --git a/lib/examples/compare-chromedp/screenshot/main.go b/lib/examples/compare-chromedp/screenshot/main.go index b447ec42..67208b4a 100644 --- a/lib/examples/compare-chromedp/screenshot/main.go +++ b/lib/examples/compare-chromedp/screenshot/main.go @@ -5,6 +5,7 @@ import ( "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" + "github.com/ysmood/gson" ) // This example demonstrates how to take a screenshot of a specific element and @@ -19,7 +20,7 @@ func main() { // capture entire browser viewport, returning jpg with quality=90 buf, err := browser.MustPage("https://brank.as/").Screenshot(true, &proto.PageCaptureScreenshot{ Format: proto.PageCaptureScreenshotFormatJpeg, - Quality: 90, + Quality: gson.Int(90), }) if err != nil { panic(err) diff --git a/lib/proto/a_interface_test.go b/lib/proto/a_interface_test.go index 02f11277..86f012a8 100644 --- a/lib/proto/a_interface_test.go +++ b/lib/proto/a_interface_test.go @@ -73,26 +73,6 @@ func (t T) TimeCodec() { t.Eq(raw, data) } -func (t T) NormalizeInputDispatchMouseEvent() { - e := proto.InputDispatchMouseEvent{ - Type: proto.InputDispatchMouseEventTypeMouseWheel, - } - - data, err := json.Marshal(e) - t.E(err) - - t.Eq(`{"type":"mouseWheel","x":0,"y":0,"deltaX":0,"deltaY":0}`, string(data)) - - ee := proto.InputDispatchMouseEvent{ - Type: proto.InputDispatchMouseEventTypeMouseMoved, - } - - data, err = json.Marshal(ee) - t.E(err) - - t.Eq(`{"type":"mouseMoved","x":0,"y":0}`, string(data)) -} - func (t T) Rect() { rect := proto.DOMQuad{ 336, 382, 361, 382, 361, 421, 336, 412, diff --git a/lib/proto/a_patch.go b/lib/proto/a_patch.go index df14a0f4..dea82d3c 100644 --- a/lib/proto/a_patch.go +++ b/lib/proto/a_patch.go @@ -3,7 +3,6 @@ package proto import ( - "encoding/json" "time" ) @@ -38,92 +37,6 @@ func (t MonotonicTime) String() string { return t.Duration().String() } -type inputDispatchMouseEvent struct { - Type InputDispatchMouseEventType `json:"type"` - X float64 `json:"x"` - Y float64 `json:"y"` - Modifiers int `json:"modifiers,omitempty"` - Timestamp TimeSinceEpoch `json:"timestamp,omitempty"` - Button InputMouseButton `json:"button,omitempty"` - Buttons int `json:"buttons,omitempty"` - ClickCount int `json:"clickCount,omitempty"` - Force float64 `json:"force,omitempty"` - TangentialPressure float64 `json:"tangentialPressure,omitempty"` - TiltX int `json:"tiltX,omitempty"` - TiltY int `json:"tiltY,omitempty"` - Twist int `json:"twist,omitempty"` - DeltaX float64 `json:"deltaX,omitempty"` - DeltaY float64 `json:"deltaY,omitempty"` - PointerType InputDispatchMouseEventPointerType `json:"pointerType,omitempty"` -} - -type inputDispatchMouseWheelEvent struct { - Type InputDispatchMouseEventType `json:"type"` - X float64 `json:"x"` - Y float64 `json:"y"` - Modifiers int `json:"modifiers,omitempty"` - Timestamp TimeSinceEpoch `json:"timestamp,omitempty"` - Button InputMouseButton `json:"button,omitempty"` - Buttons int `json:"buttons,omitempty"` - ClickCount int `json:"clickCount,omitempty"` - Force float64 `json:"force,omitempty"` - TangentialPressure float64 `json:"tangentialPressure,omitempty"` - TiltX int `json:"tiltX,omitempty"` - TiltY int `json:"tiltY,omitempty"` - Twist int `json:"twist,omitempty"` - DeltaX float64 `json:"deltaX"` - DeltaY float64 `json:"deltaY"` - PointerType InputDispatchMouseEventPointerType `json:"pointerType,omitempty"` -} - -// MarshalJSON interface -// TODO: make sure deltaX and deltaY are never omitted. Or it will cause a browser bug. -func (e InputDispatchMouseEvent) MarshalJSON() ([]byte, error) { - var ee interface{} - - if e.Type == InputDispatchMouseEventTypeMouseWheel { - ee = &inputDispatchMouseWheelEvent{ - Type: e.Type, - X: e.X, - Y: e.Y, - Modifiers: e.Modifiers, - Timestamp: e.Timestamp, - Button: e.Button, - Buttons: e.Buttons, - ClickCount: e.ClickCount, - Force: e.Force, - TangentialPressure: e.TangentialPressure, - TiltX: e.TiltX, - TiltY: e.TiltY, - Twist: e.Twist, - DeltaX: e.DeltaX, - DeltaY: e.DeltaY, - PointerType: e.PointerType, - } - } else { - ee = &inputDispatchMouseEvent{ - Type: e.Type, - X: e.X, - Y: e.Y, - Modifiers: e.Modifiers, - Timestamp: e.Timestamp, - Button: e.Button, - Buttons: e.Buttons, - ClickCount: e.ClickCount, - Force: e.Force, - TangentialPressure: e.TangentialPressure, - TiltX: e.TiltX, - TiltY: e.TiltY, - Twist: e.Twist, - DeltaX: e.DeltaX, - DeltaY: e.DeltaY, - PointerType: e.PointerType, - } - } - - return json.Marshal(ee) -} - // Point from the origin (0, 0) type Point struct { X float64 `json:"x"` diff --git a/lib/proto/accessibility.go b/lib/proto/accessibility.go index a24c681d..2f214172 100644 --- a/lib/proto/accessibility.go +++ b/lib/proto/accessibility.go @@ -429,7 +429,7 @@ type AccessibilityGetFullAXTree struct { // Depth (optional) The maximum depth at which descendants of the root node should be retrieved. // If omitted, the full tree is returned. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // FrameID (optional) The frame for whose document the AX tree should be retrieved. // If omitted, the root frame is used. diff --git a/lib/proto/audits.go b/lib/proto/audits.go index f2204735..3208fbc3 100644 --- a/lib/proto/audits.go +++ b/lib/proto/audits.go @@ -456,7 +456,7 @@ type AuditsTrustedWebActivityIssueDetails struct { ViolationType AuditsTwaQualityEnforcementViolationType `json:"violationType"` // HTTPStatusCode (optional) ... - HTTPStatusCode int `json:"httpStatusCode,omitempty"` + HTTPStatusCode *int `json:"httpStatusCode,omitempty"` // PackageName (optional) The package name of the Trusted Web Activity client app. This field is // only used when violation type is kDigitalAssetLinks. @@ -904,7 +904,7 @@ type AuditsGetEncodedResponse struct { Encoding AuditsGetEncodedResponseEncoding `json:"encoding"` // Quality (optional) The quality of the encoding (0-1). (defaults to 1) - Quality float64 `json:"quality,omitempty"` + Quality *float64 `json:"quality,omitempty"` // SizeOnly (optional) Whether to only return the size information (defaults to false). SizeOnly bool `json:"sizeOnly,omitempty"` diff --git a/lib/proto/browser.go b/lib/proto/browser.go index 4abf914d..fdd19cb1 100644 --- a/lib/proto/browser.go +++ b/lib/proto/browser.go @@ -37,16 +37,16 @@ const ( type BrowserBounds struct { // Left (optional) The offset from the left edge of the screen to the window in pixels. - Left int `json:"left,omitempty"` + Left *int `json:"left,omitempty"` // Top (optional) The offset from the top edge of the screen to the window in pixels. - Top int `json:"top,omitempty"` + Top *int `json:"top,omitempty"` // Width (optional) The window width in pixels. - Width int `json:"width,omitempty"` + Width *int `json:"width,omitempty"` // Height (optional) The window height in pixels. - Height int `json:"height,omitempty"` + Height *int `json:"height,omitempty"` // WindowState (optional) The window state. Default to normal. WindowState BrowserWindowState `json:"windowState,omitempty"` diff --git a/lib/proto/cache_storage.go b/lib/proto/cache_storage.go index 31edff66..c5b69613 100644 --- a/lib/proto/cache_storage.go +++ b/lib/proto/cache_storage.go @@ -186,10 +186,10 @@ type CacheStorageRequestEntries struct { CacheID CacheStorageCacheID `json:"cacheId"` // SkipCount (optional) Number of records to skip. - SkipCount int `json:"skipCount,omitempty"` + SkipCount *int `json:"skipCount,omitempty"` // PageSize (optional) Number of records to fetch. - PageSize int `json:"pageSize,omitempty"` + PageSize *int `json:"pageSize,omitempty"` // PathFilter (optional) If present, only return the entries containing this substring in the path PathFilter string `json:"pathFilter,omitempty"` diff --git a/lib/proto/console.go b/lib/proto/console.go index a535e3cd..a41d8977 100644 --- a/lib/proto/console.go +++ b/lib/proto/console.go @@ -84,10 +84,10 @@ type ConsoleConsoleMessage struct { URL string `json:"url,omitempty"` // Line (optional) Line number in the resource that generated this message (1-based). - Line int `json:"line,omitempty"` + Line *int `json:"line,omitempty"` // Column (optional) Column number in the resource that generated this message (1-based). - Column int `json:"column,omitempty"` + Column *int `json:"column,omitempty"` } // ConsoleClearMessages Does nothing. diff --git a/lib/proto/css.go b/lib/proto/css.go index f2941831..c75ffa13 100644 --- a/lib/proto/css.go +++ b/lib/proto/css.go @@ -362,7 +362,7 @@ type CSSMediaQueryExpression struct { ValueRange *CSSSourceRange `json:"valueRange,omitempty"` // ComputedLength (optional) Computed length of media query expression (if applicable). - ComputedLength float64 `json:"computedLength,omitempty"` + ComputedLength *float64 `json:"computedLength,omitempty"` } // CSSCSSContainerQuery (experimental) CSS container query rule descriptor. diff --git a/lib/proto/debugger.go b/lib/proto/debugger.go index f4d0e4fd..53d6eab0 100644 --- a/lib/proto/debugger.go +++ b/lib/proto/debugger.go @@ -31,7 +31,7 @@ type DebuggerLocation struct { LineNumber int `json:"lineNumber"` // ColumnNumber (optional) Column number in the script (0-based). - ColumnNumber int `json:"columnNumber,omitempty"` + ColumnNumber *int `json:"columnNumber,omitempty"` } // DebuggerScriptPosition (experimental) Location in the source code. @@ -177,7 +177,7 @@ type DebuggerBreakLocation struct { LineNumber int `json:"lineNumber"` // ColumnNumber (optional) Column number in the script (0-based). - ColumnNumber int `json:"columnNumber,omitempty"` + ColumnNumber *int `json:"columnNumber,omitempty"` // Type (optional) ... Type DebuggerBreakLocationType `json:"type,omitempty"` @@ -268,7 +268,7 @@ type DebuggerEnable struct { // MaxScriptsCacheSize (experimental) (optional) The maximum size in bytes of collected scripts (not referenced by other heap objects) // the debugger can hold. Puts no limit if parameter is omitted. - MaxScriptsCacheSize float64 `json:"maxScriptsCacheSize,omitempty"` + MaxScriptsCacheSize *float64 `json:"maxScriptsCacheSize,omitempty"` } // ProtoReq name @@ -707,7 +707,7 @@ type DebuggerSetBreakpointByURL struct { ScriptHash string `json:"scriptHash,omitempty"` // ColumnNumber (optional) Offset in the line to set breakpoint at. - ColumnNumber int `json:"columnNumber,omitempty"` + ColumnNumber *int `json:"columnNumber,omitempty"` // Condition (optional) Expression to use as a breakpoint condition. When specified, debugger will only stop on the // breakpoint if this expression evaluates to true. @@ -1093,13 +1093,13 @@ type DebuggerScriptFailedToParse struct { IsModule bool `json:"isModule,omitempty"` // Length (optional) This script length. - Length int `json:"length,omitempty"` + Length *int `json:"length,omitempty"` // StackTrace (experimental) (optional) JavaScript top stack frame of where the script parsed event was triggered if available. StackTrace *RuntimeStackTrace `json:"stackTrace,omitempty"` // CodeOffset (experimental) (optional) If the scriptLanguage is WebAssembly, the code section offset in the module. - CodeOffset int `json:"codeOffset,omitempty"` + CodeOffset *int `json:"codeOffset,omitempty"` // ScriptLanguage (experimental) (optional) The language of the script. ScriptLanguage DebuggerScriptLanguage `json:"scriptLanguage,omitempty"` @@ -1157,13 +1157,13 @@ type DebuggerScriptParsed struct { IsModule bool `json:"isModule,omitempty"` // Length (optional) This script length. - Length int `json:"length,omitempty"` + Length *int `json:"length,omitempty"` // StackTrace (experimental) (optional) JavaScript top stack frame of where the script parsed event was triggered if available. StackTrace *RuntimeStackTrace `json:"stackTrace,omitempty"` // CodeOffset (experimental) (optional) If the scriptLanguage is WebAssembly, the code section offset in the module. - CodeOffset int `json:"codeOffset,omitempty"` + CodeOffset *int `json:"codeOffset,omitempty"` // ScriptLanguage (experimental) (optional) The language of the script. ScriptLanguage DebuggerScriptLanguage `json:"scriptLanguage,omitempty"` diff --git a/lib/proto/dom.go b/lib/proto/dom.go index 8b2eaed3..9ebeecae 100644 --- a/lib/proto/dom.go +++ b/lib/proto/dom.go @@ -176,7 +176,7 @@ type DOMNode struct { NodeValue string `json:"nodeValue"` // ChildNodeCount (optional) Child count for `Container` nodes. - ChildNodeCount int `json:"childNodeCount,omitempty"` + ChildNodeCount *int `json:"childNodeCount,omitempty"` // Children (optional) Child nodes of this node when requested with children. Children []*DOMNode `json:"children,omitempty"` @@ -257,7 +257,7 @@ type DOMRGBA struct { B int `json:"b"` // A (optional) The alpha component, in the [0-1] range (default: 1). - A float64 `json:"a,omitempty"` + A *float64 `json:"a,omitempty"` } // DOMQuad An array of quad vertices, x immediately followed by y for each point, points clock-wise. @@ -397,7 +397,7 @@ type DOMDescribeNode struct { // Depth (optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the // entire subtree or provide an integer larger than 0. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // Pierce (optional) Whether or not iframes and shadow roots should be traversed when returning the subtree // (default is false). @@ -611,7 +611,7 @@ type DOMGetDocument struct { // Depth (optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the // entire subtree or provide an integer larger than 0. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // Pierce (optional) Whether or not iframes and shadow roots should be traversed when returning the subtree // (default is false). @@ -641,7 +641,7 @@ type DOMGetFlattenedDocument struct { // Depth (optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the // entire subtree or provide an integer larger than 0. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // Pierce (optional) Whether or not iframes and shadow roots should be traversed when returning the subtree // (default is false). @@ -1084,7 +1084,7 @@ type DOMRequestChildNodes struct { // Depth (optional) The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the // entire subtree or provide an integer larger than 0. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // Pierce (optional) Whether or not iframes and shadow roots should be traversed when returning the sub-tree // (default is false). diff --git a/lib/proto/dom_debugger.go b/lib/proto/dom_debugger.go index 49553b4f..fbe7098d 100644 --- a/lib/proto/dom_debugger.go +++ b/lib/proto/dom_debugger.go @@ -78,7 +78,7 @@ type DOMDebuggerGetEventListeners struct { // Depth (optional) The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the // entire subtree or provide an integer larger than 0. - Depth int `json:"depth,omitempty"` + Depth *int `json:"depth,omitempty"` // Pierce (optional) Whether or not iframes and shadow roots should be traversed when returning the subtree // (default is false). Reports listeners for all contexts if pierce is enabled. diff --git a/lib/proto/dom_snapshot.go b/lib/proto/dom_snapshot.go index f872b9a1..0dcbc3b2 100644 --- a/lib/proto/dom_snapshot.go +++ b/lib/proto/dom_snapshot.go @@ -50,7 +50,7 @@ type DOMSnapshotDOMNode struct { // LayoutNodeIndex (optional) The index of the node's related layout tree node in the `layoutTreeNodes` array returned by // `getSnapshot`, if any. - LayoutNodeIndex int `json:"layoutNodeIndex,omitempty"` + LayoutNodeIndex *int `json:"layoutNodeIndex,omitempty"` // DocumentURL (optional) Document URL that `Document` or `FrameOwner` node points to. DocumentURL string `json:"documentURL,omitempty"` @@ -75,7 +75,7 @@ type DOMSnapshotDOMNode struct { // ContentDocumentIndex (optional) The index of a frame owner element's content document in the `domNodes` array returned by // `getSnapshot`, if any. - ContentDocumentIndex int `json:"contentDocumentIndex,omitempty"` + ContentDocumentIndex *int `json:"contentDocumentIndex,omitempty"` // PseudoType (optional) Type of a pseudo element node. PseudoType DOMPseudoType `json:"pseudoType,omitempty"` @@ -98,10 +98,10 @@ type DOMSnapshotDOMNode struct { OriginURL string `json:"originURL,omitempty"` // ScrollOffsetX (optional) Scroll offsets, set when this node is a Document. - ScrollOffsetX float64 `json:"scrollOffsetX,omitempty"` + ScrollOffsetX *float64 `json:"scrollOffsetX,omitempty"` // ScrollOffsetY (optional) ... - ScrollOffsetY float64 `json:"scrollOffsetY,omitempty"` + ScrollOffsetY *float64 `json:"scrollOffsetY,omitempty"` } // DOMSnapshotInlineTextBox Details of post layout rendered text positions. The exact layout should not be regarded as @@ -136,12 +136,12 @@ type DOMSnapshotLayoutTreeNode struct { InlineTextNodes []*DOMSnapshotInlineTextBox `json:"inlineTextNodes,omitempty"` // StyleIndex (optional) Index into the `computedStyles` array returned by `getSnapshot`. - StyleIndex int `json:"styleIndex,omitempty"` + StyleIndex *int `json:"styleIndex,omitempty"` // PaintOrder (optional) Global paint order index, which is determined by the stacking order of the nodes. Nodes // that are painted together will have the same index. Only provided if includePaintOrder in // getSnapshot was true. - PaintOrder int `json:"paintOrder,omitempty"` + PaintOrder *int `json:"paintOrder,omitempty"` // IsStackingContext (optional) Set to true to indicate the element begins a new stacking context. IsStackingContext bool `json:"isStackingContext,omitempty"` @@ -237,16 +237,16 @@ type DOMSnapshotDocumentSnapshot struct { TextBoxes *DOMSnapshotTextBoxSnapshot `json:"textBoxes"` // ScrollOffsetX (optional) Horizontal scroll offset. - ScrollOffsetX float64 `json:"scrollOffsetX,omitempty"` + ScrollOffsetX *float64 `json:"scrollOffsetX,omitempty"` // ScrollOffsetY (optional) Vertical scroll offset. - ScrollOffsetY float64 `json:"scrollOffsetY,omitempty"` + ScrollOffsetY *float64 `json:"scrollOffsetY,omitempty"` // ContentWidth (optional) Document content width. - ContentWidth float64 `json:"contentWidth,omitempty"` + ContentWidth *float64 `json:"contentWidth,omitempty"` // ContentHeight (optional) Document content height. - ContentHeight float64 `json:"contentHeight,omitempty"` + ContentHeight *float64 `json:"contentHeight,omitempty"` } // DOMSnapshotNodeTreeSnapshot Table containing nodes. diff --git a/lib/proto/emulation.go b/lib/proto/emulation.go index d31a4d74..ed4b4b0d 100644 --- a/lib/proto/emulation.go +++ b/lib/proto/emulation.go @@ -292,19 +292,19 @@ type EmulationSetDeviceMetricsOverride struct { Mobile bool `json:"mobile"` // Scale (experimental) (optional) Scale to apply to resulting view image. - Scale float64 `json:"scale,omitempty"` + Scale *float64 `json:"scale,omitempty"` // ScreenWidth (experimental) (optional) Overriding screen width value in pixels (minimum 0, maximum 10000000). - ScreenWidth int `json:"screenWidth,omitempty"` + ScreenWidth *int `json:"screenWidth,omitempty"` // ScreenHeight (experimental) (optional) Overriding screen height value in pixels (minimum 0, maximum 10000000). - ScreenHeight int `json:"screenHeight,omitempty"` + ScreenHeight *int `json:"screenHeight,omitempty"` // PositionX (experimental) (optional) Overriding view X position on screen in pixels (minimum 0, maximum 10000000). - PositionX int `json:"positionX,omitempty"` + PositionX *int `json:"positionX,omitempty"` // PositionY (experimental) (optional) Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). - PositionY int `json:"positionY,omitempty"` + PositionY *int `json:"positionY,omitempty"` // DontSetVisibleSize (experimental) (optional) Do not set visible view size, rely upon explicit setVisibleSize call. DontSetVisibleSize bool `json:"dontSetVisibleSize,omitempty"` @@ -457,13 +457,13 @@ func (m EmulationSetEmulatedVisionDeficiency) Call(c Client) error { type EmulationSetGeolocationOverride struct { // Latitude (optional) Mock latitude - Latitude float64 `json:"latitude,omitempty"` + Latitude *float64 `json:"latitude,omitempty"` // Longitude (optional) Mock longitude - Longitude float64 `json:"longitude,omitempty"` + Longitude *float64 `json:"longitude,omitempty"` // Accuracy (optional) Mock accuracy - Accuracy float64 `json:"accuracy,omitempty"` + Accuracy *float64 `json:"accuracy,omitempty"` } // ProtoReq name @@ -558,7 +558,7 @@ type EmulationSetTouchEmulationEnabled struct { Enabled bool `json:"enabled"` // MaxTouchPoints (optional) Maximum touch points supported. Defaults to one. - MaxTouchPoints int `json:"maxTouchPoints,omitempty"` + MaxTouchPoints *int `json:"maxTouchPoints,omitempty"` } // ProtoReq name @@ -580,11 +580,11 @@ type EmulationSetVirtualTimePolicy struct { // Budget (optional) If set, after this many virtual milliseconds have elapsed virtual time will be paused and a // virtualTimeBudgetExpired event is sent. - Budget float64 `json:"budget,omitempty"` + Budget *float64 `json:"budget,omitempty"` // MaxVirtualTimeTaskStarvationCount (optional) If set this specifies the maximum number of tasks that can be run before virtual is forced // forwards to prevent deadlock. - MaxVirtualTimeTaskStarvationCount int `json:"maxVirtualTimeTaskStarvationCount,omitempty"` + MaxVirtualTimeTaskStarvationCount *int `json:"maxVirtualTimeTaskStarvationCount,omitempty"` // InitialVirtualTime (optional) If set, base::Time::Now will be overridden to initially return this value. InitialVirtualTime TimeSinceEpoch `json:"initialVirtualTime,omitempty"` diff --git a/lib/proto/fetch.go b/lib/proto/fetch.go index eed4262c..38e28ed7 100644 --- a/lib/proto/fetch.go +++ b/lib/proto/fetch.go @@ -253,7 +253,7 @@ type FetchContinueResponse struct { RequestID FetchRequestID `json:"requestId"` // ResponseCode (optional) An HTTP response code. If absent, original response code will be used. - ResponseCode int `json:"responseCode,omitempty"` + ResponseCode *int `json:"responseCode,omitempty"` // ResponsePhrase (optional) A textual representation of responseCode. // If absent, a standard phrase matching responseCode is used. @@ -378,7 +378,7 @@ type FetchRequestPaused struct { ResponseErrorReason NetworkErrorReason `json:"responseErrorReason,omitempty"` // ResponseStatusCode (optional) Response code if intercepted at response stage. - ResponseStatusCode int `json:"responseStatusCode,omitempty"` + ResponseStatusCode *int `json:"responseStatusCode,omitempty"` // ResponseStatusText (optional) Response status text if intercepted at response stage. ResponseStatusText string `json:"responseStatusText,omitempty"` diff --git a/lib/proto/generate/main.go b/lib/proto/generate/main.go index 0f8f1898..8f5abe0c 100644 --- a/lib/proto/generate/main.go +++ b/lib/proto/generate/main.go @@ -149,10 +149,20 @@ func (d *definition) format() (code string) { for _, prop := range d.props { tag := jsonTag(prop.originName, prop.optional) + t := prop.typeName + if prop.optional { + switch prop.typeName { + case "float64", "int": + if !strings.Contains(prop.comment(), "(default: 0)") { + t = "*" + t + } + } + } + code += utils.S(` {{.comment}} {{.name}} {{.type}} {{.tag}} - `, "comment", prop.comment(), "name", prop.name, "type", prop.typeName, "tag", tag) + `, "comment", prop.comment(), "name", prop.name, "type", t, "tag", tag) } code += "}\n" diff --git a/lib/proto/generate/patch.go b/lib/proto/generate/patch.go index 7d336c1a..827f3a76 100644 --- a/lib/proto/generate/patch.go +++ b/lib/proto/generate/patch.go @@ -61,4 +61,11 @@ func patch(json gson.JSON) { "description": "Cookie expiration date", "name": "expires", }) + + // deltaX and deltaY are not optional for mouseWheel events + j, _ = json.Gets("domains", k("domain", "Input"), "commands", k("name", "dispatchMouseEvent"), "parameters") + jj, _ := j.Gets(k("name", "deltaX")) + jj.Del("optional") + jj, _ = j.Gets(k("name", "deltaY")) + jj.Del("optional") } diff --git a/lib/proto/headless_experimental.go b/lib/proto/headless_experimental.go index a01e8bce..8419f557 100644 --- a/lib/proto/headless_experimental.go +++ b/lib/proto/headless_experimental.go @@ -28,7 +28,7 @@ type HeadlessExperimentalScreenshotParams struct { Format HeadlessExperimentalScreenshotParamsFormat `json:"format,omitempty"` // Quality (optional) Compression quality from range [0..100] (jpeg only). - Quality int `json:"quality,omitempty"` + Quality *int `json:"quality,omitempty"` } // HeadlessExperimentalBeginFrame Sends a BeginFrame to the target and returns when the frame was completed. Optionally captures a @@ -39,11 +39,11 @@ type HeadlessExperimentalBeginFrame struct { // FrameTimeTicks (optional) Timestamp of this BeginFrame in Renderer TimeTicks (milliseconds of uptime). If not set, // the current time will be used. - FrameTimeTicks float64 `json:"frameTimeTicks,omitempty"` + FrameTimeTicks *float64 `json:"frameTimeTicks,omitempty"` // Interval (optional) The interval between BeginFrames that is reported to the compositor, in milliseconds. // Defaults to a 60 frames/second interval, i.e. about 16.666 milliseconds. - Interval float64 `json:"interval,omitempty"` + Interval *float64 `json:"interval,omitempty"` // NoDisplayUpdates (optional) Whether updates should not be committed and drawn onto the display. False by default. If // true, only side effects of the BeginFrame will be run, such as layout and animations, but diff --git a/lib/proto/heap_profiler.go b/lib/proto/heap_profiler.go index 6c1aa2c0..040b91d3 100644 --- a/lib/proto/heap_profiler.go +++ b/lib/proto/heap_profiler.go @@ -181,7 +181,7 @@ type HeapProfilerStartSampling struct { // SamplingInterval (optional) Average sample interval in bytes. Poisson distribution is used for the intervals. The // default value is 32768 bytes. - SamplingInterval float64 `json:"samplingInterval,omitempty"` + SamplingInterval *float64 `json:"samplingInterval,omitempty"` } // ProtoReq name diff --git a/lib/proto/indexed_db.go b/lib/proto/indexed_db.go index 9cbe3ea1..d2914e6d 100644 --- a/lib/proto/indexed_db.go +++ b/lib/proto/indexed_db.go @@ -78,13 +78,13 @@ type IndexedDBKey struct { Type IndexedDBKeyType `json:"type"` // Number (optional) Number value. - Number float64 `json:"number,omitempty"` + Number *float64 `json:"number,omitempty"` // String (optional) String value. String string `json:"string,omitempty"` // Date (optional) Date value. - Date float64 `json:"date,omitempty"` + Date *float64 `json:"date,omitempty"` // Array (optional) Array value. Array []*IndexedDBKey `json:"array,omitempty"` diff --git a/lib/proto/input.go b/lib/proto/input.go index 0fb66920..bf3e3610 100644 --- a/lib/proto/input.go +++ b/lib/proto/input.go @@ -19,16 +19,16 @@ type InputTouchPoint struct { Y float64 `json:"y"` // RadiusX (optional) X radius of the touch area (default: 1.0). - RadiusX float64 `json:"radiusX,omitempty"` + RadiusX *float64 `json:"radiusX,omitempty"` // RadiusY (optional) Y radius of the touch area (default: 1.0). - RadiusY float64 `json:"radiusY,omitempty"` + RadiusY *float64 `json:"radiusY,omitempty"` // RotationAngle (optional) Rotation angle (default: 0.0). - RotationAngle float64 `json:"rotationAngle,omitempty"` + RotationAngle *float64 `json:"rotationAngle,omitempty"` // Force (optional) Force (default: 1.0). - Force float64 `json:"force,omitempty"` + Force *float64 `json:"force,omitempty"` // TangentialPressure (experimental) (optional) The normalized tangential pressure, which has a range of [-1,1] (default: 0). TangentialPressure float64 `json:"tangentialPressure,omitempty"` @@ -43,7 +43,7 @@ type InputTouchPoint struct { Twist int `json:"twist,omitempty"` // ID (optional) Identifier used to track touch sources between events, must be unique within an event. - ID float64 `json:"id,omitempty"` + ID *float64 `json:"id,omitempty"` } // InputGestureSourceType (experimental) ... @@ -225,7 +225,7 @@ type InputDispatchKeyEvent struct { // Location (optional) Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default: // 0). - Location int `json:"location,omitempty"` + Location *int `json:"location,omitempty"` // Commands (experimental) (optional) Editing commands to send with the key event (e.g., 'selectAll') (default: []). // These are related to but not equal the command names used in `document.execCommand` and NSStandardKeyBindingResponding. @@ -272,10 +272,10 @@ type InputImeSetComposition struct { SelectionEnd int `json:"selectionEnd"` // ReplacementStart (optional) replacement start - ReplacementStart int `json:"replacementStart,omitempty"` + ReplacementStart *int `json:"replacementStart,omitempty"` // ReplacementEnd (optional) replacement end - ReplacementEnd int `json:"replacementEnd,omitempty"` + ReplacementEnd *int `json:"replacementEnd,omitempty"` } // ProtoReq name @@ -339,7 +339,7 @@ type InputDispatchMouseEvent struct { // Buttons (optional) A number indicating which buttons are pressed on the mouse when a mouse event is triggered. // Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0. - Buttons int `json:"buttons,omitempty"` + Buttons *int `json:"buttons,omitempty"` // ClickCount (optional) Number of times the mouse button was clicked (default: 0). ClickCount int `json:"clickCount,omitempty"` @@ -359,11 +359,11 @@ type InputDispatchMouseEvent struct { // Twist (experimental) (optional) The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0). Twist int `json:"twist,omitempty"` - // DeltaX (optional) X delta in CSS pixels for mouse wheel event (default: 0). - DeltaX float64 `json:"deltaX,omitempty"` + // DeltaX X delta in CSS pixels for mouse wheel event (default: 0). + DeltaX float64 `json:"deltaX"` - // DeltaY (optional) Y delta in CSS pixels for mouse wheel event (default: 0). - DeltaY float64 `json:"deltaY,omitempty"` + // DeltaY Y delta in CSS pixels for mouse wheel event (default: 0). + DeltaY float64 `json:"deltaY"` // PointerType (optional) Pointer type (default: "mouse"). PointerType InputDispatchMouseEventPointerType `json:"pointerType,omitempty"` @@ -523,7 +523,7 @@ type InputSynthesizePinchGesture struct { ScaleFactor float64 `json:"scaleFactor"` // RelativeSpeed (optional) Relative pointer speed in pixels per second (default: 800). - RelativeSpeed int `json:"relativeSpeed,omitempty"` + RelativeSpeed *int `json:"relativeSpeed,omitempty"` // GestureSourceType (optional) Which type of input events to be generated (default: 'default', which queries the platform // for the preferred input type). @@ -548,24 +548,24 @@ type InputSynthesizeScrollGesture struct { Y float64 `json:"y"` // XDistance (optional) The distance to scroll along the X axis (positive to scroll left). - XDistance float64 `json:"xDistance,omitempty"` + XDistance *float64 `json:"xDistance,omitempty"` // YDistance (optional) The distance to scroll along the Y axis (positive to scroll up). - YDistance float64 `json:"yDistance,omitempty"` + YDistance *float64 `json:"yDistance,omitempty"` // XOverscroll (optional) The number of additional pixels to scroll back along the X axis, in addition to the given // distance. - XOverscroll float64 `json:"xOverscroll,omitempty"` + XOverscroll *float64 `json:"xOverscroll,omitempty"` // YOverscroll (optional) The number of additional pixels to scroll back along the Y axis, in addition to the given // distance. - YOverscroll float64 `json:"yOverscroll,omitempty"` + YOverscroll *float64 `json:"yOverscroll,omitempty"` // PreventFling (optional) Prevent fling (default: true). PreventFling bool `json:"preventFling,omitempty"` // Speed (optional) Swipe speed in pixels per second (default: 800). - Speed int `json:"speed,omitempty"` + Speed *int `json:"speed,omitempty"` // GestureSourceType (optional) Which type of input events to be generated (default: 'default', which queries the platform // for the preferred input type). @@ -575,7 +575,7 @@ type InputSynthesizeScrollGesture struct { RepeatCount int `json:"repeatCount,omitempty"` // RepeatDelayMs (optional) The number of milliseconds delay between each repeat. (default: 250). - RepeatDelayMs int `json:"repeatDelayMs,omitempty"` + RepeatDelayMs *int `json:"repeatDelayMs,omitempty"` // InteractionMarkerName (optional) The name of the interaction markers to generate, if not empty (default: ""). InteractionMarkerName string `json:"interactionMarkerName,omitempty"` @@ -599,10 +599,10 @@ type InputSynthesizeTapGesture struct { Y float64 `json:"y"` // Duration (optional) Duration between touchdown and touchup events in ms (default: 50). - Duration int `json:"duration,omitempty"` + Duration *int `json:"duration,omitempty"` // TapCount (optional) Number of times to perform the tap (e.g. 2 for double tap, default: 1). - TapCount int `json:"tapCount,omitempty"` + TapCount *int `json:"tapCount,omitempty"` // GestureSourceType (optional) Which type of input events to be generated (default: 'default', which queries the platform // for the preferred input type). diff --git a/lib/proto/io.go b/lib/proto/io.go index ea5a25bd..f068138c 100644 --- a/lib/proto/io.go +++ b/lib/proto/io.go @@ -37,10 +37,10 @@ type IORead struct { // Offset (optional) Seek to the specified offset before reading (if not specificed, proceed with offset // following the last read). Some types of streams may only support sequential reads. - Offset int `json:"offset,omitempty"` + Offset *int `json:"offset,omitempty"` // Size (optional) Maximum number of bytes to read (left upon the agent discretion if not specified). - Size int `json:"size,omitempty"` + Size *int `json:"size,omitempty"` } // ProtoReq name diff --git a/lib/proto/layer_tree.go b/lib/proto/layer_tree.go index b2795be0..eed42190 100644 --- a/lib/proto/layer_tree.go +++ b/lib/proto/layer_tree.go @@ -99,13 +99,13 @@ type LayerTreeLayer struct { Transform []float64 `json:"transform,omitempty"` // AnchorX (optional) Transform anchor point X, absent if no transform specified - AnchorX float64 `json:"anchorX,omitempty"` + AnchorX *float64 `json:"anchorX,omitempty"` // AnchorY (optional) Transform anchor point Y, absent if no transform specified - AnchorY float64 `json:"anchorY,omitempty"` + AnchorY *float64 `json:"anchorY,omitempty"` // AnchorZ (optional) Transform anchor point Z, absent if no transform specified - AnchorZ float64 `json:"anchorZ,omitempty"` + AnchorZ *float64 `json:"anchorZ,omitempty"` // PaintCount Indicates how many time this layer has painted. PaintCount int `json:"paintCount"` @@ -230,10 +230,10 @@ type LayerTreeProfileSnapshot struct { SnapshotID LayerTreeSnapshotID `json:"snapshotId"` // MinRepeatCount (optional) The maximum number of times to replay the snapshot (1, if not specified). - MinRepeatCount int `json:"minRepeatCount,omitempty"` + MinRepeatCount *int `json:"minRepeatCount,omitempty"` // MinDuration (optional) The minimum duration (in seconds) to replay the snapshot. - MinDuration float64 `json:"minDuration,omitempty"` + MinDuration *float64 `json:"minDuration,omitempty"` // ClipRect (optional) The clip rectangle to apply when replaying the snapshot. ClipRect *DOMRect `json:"clipRect,omitempty"` @@ -277,13 +277,13 @@ type LayerTreeReplaySnapshot struct { SnapshotID LayerTreeSnapshotID `json:"snapshotId"` // FromStep (optional) The first step to replay from (replay from the very start if not specified). - FromStep int `json:"fromStep,omitempty"` + FromStep *int `json:"fromStep,omitempty"` // ToStep (optional) The last step to replay to (replay till the end if not specified). - ToStep int `json:"toStep,omitempty"` + ToStep *int `json:"toStep,omitempty"` // Scale (optional) The scale to apply while replaying (defaults to 1). - Scale float64 `json:"scale,omitempty"` + Scale *float64 `json:"scale,omitempty"` } // ProtoReq name diff --git a/lib/proto/log.go b/lib/proto/log.go index 46c06058..c74347c1 100644 --- a/lib/proto/log.go +++ b/lib/proto/log.go @@ -101,7 +101,7 @@ type LogLogEntry struct { URL string `json:"url,omitempty"` // LineNumber (optional) Line number in the resource. - LineNumber int `json:"lineNumber,omitempty"` + LineNumber *int `json:"lineNumber,omitempty"` // StackTrace (optional) JavaScript stack trace. StackTrace *RuntimeStackTrace `json:"stackTrace,omitempty"` diff --git a/lib/proto/memory.go b/lib/proto/memory.go index a0e6af17..fa200a6e 100644 --- a/lib/proto/memory.go +++ b/lib/proto/memory.go @@ -149,7 +149,7 @@ func (m MemorySimulatePressureNotification) Call(c Client) error { type MemoryStartSampling struct { // SamplingInterval (optional) Average number of bytes between samples. - SamplingInterval int `json:"samplingInterval,omitempty"` + SamplingInterval *int `json:"samplingInterval,omitempty"` // SuppressRandomness (optional) Do not randomize intervals between samples. SuppressRandomness bool `json:"suppressRandomness,omitempty"` diff --git a/lib/proto/network.go b/lib/proto/network.go index 548047a6..1eb5eb83 100644 --- a/lib/proto/network.go +++ b/lib/proto/network.go @@ -696,7 +696,7 @@ type NetworkResponse struct { RemoteIPAddress string `json:"remoteIPAddress,omitempty"` // RemotePort (optional) Remote port. - RemotePort int `json:"remotePort,omitempty"` + RemotePort *int `json:"remotePort,omitempty"` // FromDiskCache (optional) Specifies that the request was served from the disk cache. FromDiskCache bool `json:"fromDiskCache,omitempty"` @@ -829,11 +829,11 @@ type NetworkInitiator struct { // LineNumber (optional) Initiator line number, set for Parser type or for Script type (when script is importing // module) (0-based). - LineNumber float64 `json:"lineNumber,omitempty"` + LineNumber *float64 `json:"lineNumber,omitempty"` // ColumnNumber (optional) Initiator column number, set for Parser type or for Script type (when script is importing // module) (0-based). - ColumnNumber float64 `json:"columnNumber,omitempty"` + ColumnNumber *float64 `json:"columnNumber,omitempty"` // RequestID (optional) Set if another request triggered this request (e.g. preflight). RequestID NetworkRequestID `json:"requestId,omitempty"` @@ -1069,7 +1069,7 @@ type NetworkCookieParam struct { // SourcePort (experimental) (optional) Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port. // An unspecified port value allows protocol clients to emulate legacy cookie scope for the port. // This is a temporary ability and it will be removed in the future. - SourcePort int `json:"sourcePort,omitempty"` + SourcePort *int `json:"sourcePort,omitempty"` // PartitionKey (experimental) (optional) Cookie partition key. The site of the top-level URL the browser was visiting at the start // of the request to the endpoint that set the cookie. @@ -1243,7 +1243,7 @@ type NetworkSignedExchangeError struct { Message string `json:"message"` // SignatureIndex (optional) The index of the signature which caused the error. - SignatureIndex int `json:"signatureIndex,omitempty"` + SignatureIndex *int `json:"signatureIndex,omitempty"` // ErrorField (optional) The field which caused the error. ErrorField NetworkSignedExchangeErrorField `json:"errorField,omitempty"` @@ -1482,13 +1482,13 @@ type NetworkLoadNetworkResourcePageResult struct { Success bool `json:"success"` // NetError (optional) Optional values used for error reporting. - NetError float64 `json:"netError,omitempty"` + NetError *float64 `json:"netError,omitempty"` // NetErrorName (optional) ... NetErrorName string `json:"netErrorName,omitempty"` // HTTPStatusCode (optional) ... - HTTPStatusCode float64 `json:"httpStatusCode,omitempty"` + HTTPStatusCode *float64 `json:"httpStatusCode,omitempty"` // Stream (optional) If successful, one of the following two fields holds the result. Stream IOStreamHandle `json:"stream,omitempty"` @@ -1739,13 +1739,13 @@ func (m NetworkEmulateNetworkConditions) Call(c Client) error { type NetworkEnable struct { // MaxTotalBufferSize (experimental) (optional) Buffer size in bytes to use when preserving network payloads (XHRs, etc). - MaxTotalBufferSize int `json:"maxTotalBufferSize,omitempty"` + MaxTotalBufferSize *int `json:"maxTotalBufferSize,omitempty"` // MaxResourceBufferSize (experimental) (optional) Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc). - MaxResourceBufferSize int `json:"maxResourceBufferSize,omitempty"` + MaxResourceBufferSize *int `json:"maxResourceBufferSize,omitempty"` // MaxPostDataSize (optional) Longest post body size (in bytes) that would be included in requestWillBeSent notification - MaxPostDataSize int `json:"maxPostDataSize,omitempty"` + MaxPostDataSize *int `json:"maxPostDataSize,omitempty"` } // ProtoReq name @@ -2073,7 +2073,7 @@ type NetworkSetCookie struct { // SourcePort (experimental) (optional) Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port. // An unspecified port value allows protocol clients to emulate legacy cookie scope for the port. // This is a temporary ability and it will be removed in the future. - SourcePort int `json:"sourcePort,omitempty"` + SourcePort *int `json:"sourcePort,omitempty"` // PartitionKey (experimental) (optional) Cookie partition key. The site of the top-level URL the browser was visiting at the start // of the request to the endpoint that set the cookie. @@ -2390,7 +2390,7 @@ type NetworkRequestIntercepted struct { // ResponseStatusCode (optional) Response code if intercepted at response stage or if redirect occurred while intercepting // request or auth retry occurred. - ResponseStatusCode int `json:"responseStatusCode,omitempty"` + ResponseStatusCode *int `json:"responseStatusCode,omitempty"` // ResponseHeaders (optional) Response headers if intercepted at the response stage or if redirect occurred while // intercepting request or auth retry occurred. @@ -2829,7 +2829,7 @@ type NetworkTrustTokenOperationDone struct { IssuerOrigin string `json:"issuerOrigin,omitempty"` // IssuedTokenCount (optional) The number of obtained Trust Tokens on a successful "Issuance" operation. - IssuedTokenCount int `json:"issuedTokenCount,omitempty"` + IssuedTokenCount *int `json:"issuedTokenCount,omitempty"` } // ProtoEvent name diff --git a/lib/proto/page.go b/lib/proto/page.go index 4dc5666d..a8c9871d 100644 --- a/lib/proto/page.go +++ b/lib/proto/page.go @@ -527,7 +527,7 @@ type PageFrameResource struct { LastModified TimeSinceEpoch `json:"lastModified,omitempty"` // ContentSize (optional) Resource content size. - ContentSize float64 `json:"contentSize,omitempty"` + ContentSize *float64 `json:"contentSize,omitempty"` // Failed (optional) True if the resource failed to load. Failed bool `json:"failed,omitempty"` @@ -731,7 +731,7 @@ type PageVisualViewport struct { Scale float64 `json:"scale"` // Zoom (optional) Page zoom factor (CSS to device independent pixels ratio). - Zoom float64 `json:"zoom,omitempty"` + Zoom *float64 `json:"zoom,omitempty"` } // PageViewport Viewport for capturing screenshot. @@ -792,10 +792,10 @@ type PageScriptFontFamilies struct { type PageFontSizes struct { // Standard (optional) Default standard font size. - Standard int `json:"standard,omitempty"` + Standard *int `json:"standard,omitempty"` // Fixed (optional) Default fixed font size. - Fixed int `json:"fixed,omitempty"` + Fixed *int `json:"fixed,omitempty"` } // PageClientNavigationReason (experimental) ... @@ -1424,7 +1424,7 @@ type PageCaptureScreenshot struct { Format PageCaptureScreenshotFormat `json:"format,omitempty"` // Quality (optional) Compression quality from range [0..100] (jpeg only). - Quality int `json:"quality,omitempty"` + Quality *int `json:"quality,omitempty"` // Clip (optional) Capture the screenshot of a given region only. Clip *PageViewport `json:"clip,omitempty"` @@ -1949,25 +1949,25 @@ type PagePrintToPDF struct { PrintBackground bool `json:"printBackground,omitempty"` // Scale (optional) Scale of the webpage rendering. Defaults to 1. - Scale float64 `json:"scale,omitempty"` + Scale *float64 `json:"scale,omitempty"` // PaperWidth (optional) Paper width in inches. Defaults to 8.5 inches. - PaperWidth float64 `json:"paperWidth,omitempty"` + PaperWidth *float64 `json:"paperWidth,omitempty"` // PaperHeight (optional) Paper height in inches. Defaults to 11 inches. - PaperHeight float64 `json:"paperHeight,omitempty"` + PaperHeight *float64 `json:"paperHeight,omitempty"` // MarginTop (optional) Top margin in inches. Defaults to 1cm (~0.4 inches). - MarginTop float64 `json:"marginTop,omitempty"` + MarginTop *float64 `json:"marginTop,omitempty"` // MarginBottom (optional) Bottom margin in inches. Defaults to 1cm (~0.4 inches). - MarginBottom float64 `json:"marginBottom,omitempty"` + MarginBottom *float64 `json:"marginBottom,omitempty"` // MarginLeft (optional) Left margin in inches. Defaults to 1cm (~0.4 inches). - MarginLeft float64 `json:"marginLeft,omitempty"` + MarginLeft *float64 `json:"marginLeft,omitempty"` // MarginRight (optional) Right margin in inches. Defaults to 1cm (~0.4 inches). - MarginRight float64 `json:"marginRight,omitempty"` + MarginRight *float64 `json:"marginRight,omitempty"` // PageRanges (optional) Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means // print all pages. @@ -2216,19 +2216,19 @@ type PageSetDeviceMetricsOverride struct { Mobile bool `json:"mobile"` // Scale (optional) Scale to apply to resulting view image. - Scale float64 `json:"scale,omitempty"` + Scale *float64 `json:"scale,omitempty"` // ScreenWidth (optional) Overriding screen width value in pixels (minimum 0, maximum 10000000). - ScreenWidth int `json:"screenWidth,omitempty"` + ScreenWidth *int `json:"screenWidth,omitempty"` // ScreenHeight (optional) Overriding screen height value in pixels (minimum 0, maximum 10000000). - ScreenHeight int `json:"screenHeight,omitempty"` + ScreenHeight *int `json:"screenHeight,omitempty"` // PositionX (optional) Overriding view X position on screen in pixels (minimum 0, maximum 10000000). - PositionX int `json:"positionX,omitempty"` + PositionX *int `json:"positionX,omitempty"` // PositionY (optional) Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). - PositionY int `json:"positionY,omitempty"` + PositionY *int `json:"positionY,omitempty"` // DontSetVisibleSize (optional) Do not set visible view size, rely upon explicit setVisibleSize call. DontSetVisibleSize bool `json:"dontSetVisibleSize,omitempty"` @@ -2360,13 +2360,13 @@ func (m PageSetDownloadBehavior) Call(c Client) error { type PageSetGeolocationOverride struct { // Latitude (optional) Mock latitude - Latitude float64 `json:"latitude,omitempty"` + Latitude *float64 `json:"latitude,omitempty"` // Longitude (optional) Mock longitude - Longitude float64 `json:"longitude,omitempty"` + Longitude *float64 `json:"longitude,omitempty"` // Accuracy (optional) Mock accuracy - Accuracy float64 `json:"accuracy,omitempty"` + Accuracy *float64 `json:"accuracy,omitempty"` } // ProtoReq name @@ -2439,16 +2439,16 @@ type PageStartScreencast struct { Format PageStartScreencastFormat `json:"format,omitempty"` // Quality (optional) Compression quality from range [0..100]. - Quality int `json:"quality,omitempty"` + Quality *int `json:"quality,omitempty"` // MaxWidth (optional) Maximum screenshot width. - MaxWidth int `json:"maxWidth,omitempty"` + MaxWidth *int `json:"maxWidth,omitempty"` // MaxHeight (optional) Maximum screenshot height. - MaxHeight int `json:"maxHeight,omitempty"` + MaxHeight *int `json:"maxHeight,omitempty"` // EveryNthFrame (optional) Send every n-th frame. - EveryNthFrame int `json:"everyNthFrame,omitempty"` + EveryNthFrame *int `json:"everyNthFrame,omitempty"` } // ProtoReq name diff --git a/lib/proto/performance_timeline.go b/lib/proto/performance_timeline.go index 8a8710f6..0fbbb8cd 100644 --- a/lib/proto/performance_timeline.go +++ b/lib/proto/performance_timeline.go @@ -79,7 +79,7 @@ type PerformanceTimelineTimelineEvent struct { Time TimeSinceEpoch `json:"time"` // Duration (optional) Event duration, if applicable. - Duration float64 `json:"duration,omitempty"` + Duration *float64 `json:"duration,omitempty"` // LcpDetails (optional) ... LcpDetails *PerformanceTimelineLargestContentfulPaint `json:"lcpDetails,omitempty"` diff --git a/lib/proto/profiler.go b/lib/proto/profiler.go index 450c8c64..d34adfec 100644 --- a/lib/proto/profiler.go +++ b/lib/proto/profiler.go @@ -18,7 +18,7 @@ type ProfilerProfileNode struct { CallFrame *RuntimeCallFrame `json:"callFrame"` // HitCount (optional) Number of samples where this node was on top of the call stack. - HitCount int `json:"hitCount,omitempty"` + HitCount *int `json:"hitCount,omitempty"` // Children (optional) Child node ids. Children []int `json:"children,omitempty"` diff --git a/lib/proto/service_worker.go b/lib/proto/service_worker.go index b049b23d..d25e1207 100644 --- a/lib/proto/service_worker.go +++ b/lib/proto/service_worker.go @@ -83,11 +83,11 @@ type ServiceWorkerServiceWorkerVersion struct { Status ServiceWorkerServiceWorkerVersionStatus `json:"status"` // ScriptLastModified (optional) The Last-Modified header value of the main script. - ScriptLastModified float64 `json:"scriptLastModified,omitempty"` + ScriptLastModified *float64 `json:"scriptLastModified,omitempty"` // ScriptResponseTime (optional) The time at which the response headers of the main script were received from the server. // For cached script it is the last time the cache entry was validated. - ScriptResponseTime float64 `json:"scriptResponseTime,omitempty"` + ScriptResponseTime *float64 `json:"scriptResponseTime,omitempty"` // ControlledClients (optional) ... ControlledClients []TargetTargetID `json:"controlledClients,omitempty"` diff --git a/lib/proto/storage.go b/lib/proto/storage.go index 48414362..ca10e7d6 100644 --- a/lib/proto/storage.go +++ b/lib/proto/storage.go @@ -259,7 +259,7 @@ type StorageOverrideQuotaForOrigin struct { // the specified origin. If this is called multiple times with different // origins, the override will be maintained for each origin until it is // disabled (called without a quotaSize). - QuotaSize float64 `json:"quotaSize,omitempty"` + QuotaSize *float64 `json:"quotaSize,omitempty"` } // ProtoReq name diff --git a/lib/proto/system_info.go b/lib/proto/system_info.go index 7505b034..10bc5ae7 100644 --- a/lib/proto/system_info.go +++ b/lib/proto/system_info.go @@ -24,10 +24,10 @@ type SystemInfoGPUDevice struct { DeviceID float64 `json:"deviceId"` // SubSysID (optional) Sub sys ID of the GPU, only available on Windows. - SubSysID float64 `json:"subSysId,omitempty"` + SubSysID *float64 `json:"subSysId,omitempty"` // Revision (optional) Revision of the GPU, only available on Windows. - Revision float64 `json:"revision,omitempty"` + Revision *float64 `json:"revision,omitempty"` // VendorString String description of the GPU vendor, if the PCI ID is not available. VendorString string `json:"vendorString"` diff --git a/lib/proto/target.go b/lib/proto/target.go index ec6b5f8d..eab2bea4 100644 --- a/lib/proto/target.go +++ b/lib/proto/target.go @@ -253,10 +253,10 @@ type TargetCreateTarget struct { URL string `json:"url"` // Width (optional) Frame width in DIP (headless chrome only). - Width int `json:"width,omitempty"` + Width *int `json:"width,omitempty"` // Height (optional) Frame height in DIP (headless chrome only). - Height int `json:"height,omitempty"` + Height *int `json:"height,omitempty"` // BrowserContextID (experimental) (optional) The browser context to create the page in. BrowserContextID BrowserBrowserContextID `json:"browserContextId,omitempty"` diff --git a/lib/proto/tracing.go b/lib/proto/tracing.go index efa9dd05..3152a190 100644 --- a/lib/proto/tracing.go +++ b/lib/proto/tracing.go @@ -214,7 +214,7 @@ type TracingStart struct { Options string `json:"options,omitempty"` // BufferUsageReportingInterval (optional) If set, the agent will issue bufferUsage events at this interval, specified in milliseconds - BufferUsageReportingInterval float64 `json:"bufferUsageReportingInterval,omitempty"` + BufferUsageReportingInterval *float64 `json:"bufferUsageReportingInterval,omitempty"` // TransferMode (optional) Whether to report trace events as series of dataCollected events or to save trace to a // stream (defaults to `ReportEvents`). @@ -253,14 +253,14 @@ type TracingBufferUsage struct { // PercentFull (optional) A number in range [0..1] that indicates the used size of event buffer as a fraction of its // total size. - PercentFull float64 `json:"percentFull,omitempty"` + PercentFull *float64 `json:"percentFull,omitempty"` // EventCount (optional) An approximate number of events in the trace log. - EventCount float64 `json:"eventCount,omitempty"` + EventCount *float64 `json:"eventCount,omitempty"` // Value (optional) A number in range [0..1] that indicates the used size of event buffer as a fraction of its // total size. - Value float64 `json:"value,omitempty"` + Value *float64 `json:"value,omitempty"` } // ProtoEvent name diff --git a/lib/proto/web_audio.go b/lib/proto/web_audio.go index 5659dea3..e60dda2d 100644 --- a/lib/proto/web_audio.go +++ b/lib/proto/web_audio.go @@ -370,10 +370,10 @@ type WebAudioNodesConnected struct { DestinationID WebAudioGraphObjectID `json:"destinationId"` // SourceOutputIndex (optional) ... - SourceOutputIndex float64 `json:"sourceOutputIndex,omitempty"` + SourceOutputIndex *float64 `json:"sourceOutputIndex,omitempty"` // DestinationInputIndex (optional) ... - DestinationInputIndex float64 `json:"destinationInputIndex,omitempty"` + DestinationInputIndex *float64 `json:"destinationInputIndex,omitempty"` } // ProtoEvent name @@ -394,10 +394,10 @@ type WebAudioNodesDisconnected struct { DestinationID WebAudioGraphObjectID `json:"destinationId"` // SourceOutputIndex (optional) ... - SourceOutputIndex float64 `json:"sourceOutputIndex,omitempty"` + SourceOutputIndex *float64 `json:"sourceOutputIndex,omitempty"` // DestinationInputIndex (optional) ... - DestinationInputIndex float64 `json:"destinationInputIndex,omitempty"` + DestinationInputIndex *float64 `json:"destinationInputIndex,omitempty"` } // ProtoEvent name @@ -418,7 +418,7 @@ type WebAudioNodeParamConnected struct { DestinationID WebAudioGraphObjectID `json:"destinationId"` // SourceOutputIndex (optional) ... - SourceOutputIndex float64 `json:"sourceOutputIndex,omitempty"` + SourceOutputIndex *float64 `json:"sourceOutputIndex,omitempty"` } // ProtoEvent name @@ -439,7 +439,7 @@ type WebAudioNodeParamDisconnected struct { DestinationID WebAudioGraphObjectID `json:"destinationId"` // SourceOutputIndex (optional) ... - SourceOutputIndex float64 `json:"sourceOutputIndex,omitempty"` + SourceOutputIndex *float64 `json:"sourceOutputIndex,omitempty"` } // ProtoEvent name diff --git a/must.go b/must.go index 25372560..90a77af1 100644 --- a/must.go +++ b/must.go @@ -253,10 +253,10 @@ func (p *Page) MustGetWindow() *proto.BrowserBounds { // MustSetWindow is similar to Page.SetWindow func (p *Page) MustSetWindow(left, top, width, height int) *Page { p.e(p.SetWindow(&proto.BrowserBounds{ - Left: left, - Top: top, - Width: width, - Height: height, + Left: gson.Int(left), + Top: gson.Int(top), + Width: gson.Int(width), + Height: gson.Int(height), WindowState: proto.BrowserWindowStateNormal, })) return p diff --git a/page_test.go b/page_test.go index 3f323415..e294e0bc 100644 --- a/page_test.go +++ b/page_test.go @@ -200,10 +200,10 @@ func TestWindow(t *testing.T) { bounds := page.MustGetWindow() defer page.MustSetWindow( - bounds.Left, - bounds.Top, - bounds.Width, - bounds.Height, + *bounds.Left, + *bounds.Top, + *bounds.Width, + *bounds.Height, ) page.MustWindowMaximize() diff --git a/utils.go b/utils.go index 66291f7a..9c95cfcf 100644 --- a/utils.go +++ b/utils.go @@ -158,7 +158,7 @@ var _ io.ReadCloser = &StreamReader{} // StreamReader for browser data stream type StreamReader struct { - Offset int + Offset *int c proto.Client handle proto.IOStreamHandle