diff --git a/target/easyjson.go b/target/easyjson.go index 1d33071..652696c 100644 --- a/target/easyjson.go +++ b/target/easyjson.go @@ -2038,6 +2038,8 @@ func easyjsonC5a4559bDecodeGithubComChromedpCdprotoTarget23(in *jlexer.Lexer, ou out.Width = int64(in.Int64()) case "height": out.Height = int64(in.Int64()) + case "windowState": + (out.WindowState).UnmarshalEasyJSON(in) case "browserContextId": out.BrowserContextID = cdp.BrowserContextID(in.String()) case "enableBeginFrameControl": @@ -2087,6 +2089,11 @@ func easyjsonC5a4559bEncodeGithubComChromedpCdprotoTarget23(out *jwriter.Writer, out.RawString(prefix) out.Int64(int64(in.Height)) } + if in.WindowState != "" { + const prefix string = ",\"windowState\":" + out.RawString(prefix) + (in.WindowState).MarshalEasyJSON(out) + } if in.BrowserContextID != "" { const prefix string = ",\"browserContextId\":" out.RawString(prefix) diff --git a/target/target.go b/target/target.go index 86ccb28..9661fa9 100644 --- a/target/target.go +++ b/target/target.go @@ -291,6 +291,7 @@ type CreateTargetParams struct { Top int64 `json:"top,omitempty"` // Frame top origin in DIP (requires newWindow to be true or headless shell). Width int64 `json:"width,omitempty"` // Frame width in DIP (requires newWindow to be true or headless shell). Height int64 `json:"height,omitempty"` // Frame height in DIP (requires newWindow to be true or headless shell). + WindowState WindowState `json:"windowState,omitempty"` // Frame window state (requires newWindow to be true or headless shell). Default is normal. BrowserContextID cdp.BrowserContextID `json:"browserContextId,omitempty"` // The browser context to create the page in. EnableBeginFrameControl bool `json:"enableBeginFrameControl,omitempty"` // Whether BeginFrames for this target will be controlled via DevTools (headless shell only, not supported on MacOS yet, false by default). NewWindow bool `json:"newWindow,omitempty"` // Whether to create a new Window or Tab (false by default, not supported by headless shell). @@ -339,6 +340,13 @@ func (p CreateTargetParams) WithHeight(height int64) *CreateTargetParams { return &p } +// WithWindowState frame window state (requires newWindow to be true or +// headless shell). Default is normal. +func (p CreateTargetParams) WithWindowState(windowState WindowState) *CreateTargetParams { + p.WindowState = windowState + return &p +} + // WithBrowserContextID the browser context to create the page in. func (p CreateTargetParams) WithBrowserContextID(browserContextID cdp.BrowserContextID) *CreateTargetParams { p.BrowserContextID = browserContextID diff --git a/target/types.go b/target/types.go index b13c99a..284755d 100644 --- a/target/types.go +++ b/target/types.go @@ -3,7 +3,12 @@ package target // Code generated by cdproto-gen. DO NOT EDIT. import ( + "fmt" + "github.com/chromedp/cdproto/cdp" + "github.com/mailru/easyjson" + "github.com/mailru/easyjson/jlexer" + "github.com/mailru/easyjson/jwriter" ) // ID [no description]. @@ -70,3 +75,54 @@ type RemoteLocation struct { Host string `json:"host"` Port int64 `json:"port"` } + +// WindowState the state of the target window. +// +// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#type-WindowState +type WindowState string + +// String returns the WindowState as string value. +func (t WindowState) String() string { + return string(t) +} + +// WindowState values. +const ( + WindowStateNormal WindowState = "normal" + WindowStateMinimized WindowState = "minimized" + WindowStateMaximized WindowState = "maximized" + WindowStateFullscreen WindowState = "fullscreen" +) + +// MarshalEasyJSON satisfies easyjson.Marshaler. +func (t WindowState) MarshalEasyJSON(out *jwriter.Writer) { + out.String(string(t)) +} + +// MarshalJSON satisfies json.Marshaler. +func (t WindowState) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *WindowState) UnmarshalEasyJSON(in *jlexer.Lexer) { + v := in.String() + switch WindowState(v) { + case WindowStateNormal: + *t = WindowStateNormal + case WindowStateMinimized: + *t = WindowStateMinimized + case WindowStateMaximized: + *t = WindowStateMaximized + case WindowStateFullscreen: + *t = WindowStateFullscreen + + default: + in.AddError(fmt.Errorf("unknown WindowState value: %v", v)) + } +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *WindowState) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +}