commit 20d575fece73a6e8284d9fa8efc46fbaa848c96b Author: Kenneth Shaw Date: Tue Jan 24 22:09:23 2017 +0700 Initial import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2ddf74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +out.txt +out*.txt +old*.txt + +# binaries +/chromedp-gen +/cmd/chromedp-gen/chromedp-gen diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8e2e6c2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016-2017 Kenneth Shaw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e45a6f0 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# About chromedp + +Package chromedp is a faster, simpler way to drive browsers in Go using the +[Chrome Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) +(for Chrome, Edge, Safari, etc) without external dependencies (ie, Selenium, PhantomJS, etc). + +**NOTE:** chromedp's API is currently unstable, and may change at a moments +notice. There are likely extremely bad bugs lurking in this code. **CAVEAT USER**. + +## Installation + +Install in the usual way: + +```sh +go get -u github.com/knq/chromedp +``` + +## Usage + +Please see the [examples](examples/) directory for examples. + +## TODO +* Move timeouts to context (defaults) +* Implement more query selector options (allow over riding context timeouts) +* Contextual actions for "dry run" (or via an accumulator?) +* Network loader / manager +* More examples +* Profiler +* Unit tests / coverage: travis-ci + coveralls integration diff --git a/actions.go b/actions.go new file mode 100644 index 0000000..fae2721 --- /dev/null +++ b/actions.go @@ -0,0 +1,49 @@ +package chromedp + +import ( + "context" + "time" + + . "github.com/knq/chromedp/cdp" +) + +// Action is a single atomic action. +type Action interface { + Do(context.Context, FrameHandler) error +} + +// ActionFunc is a single action func. +type ActionFunc func(context.Context, FrameHandler) error + +// Do executes the action using the provided context. +func (f ActionFunc) Do(ctxt context.Context, h FrameHandler) error { + return f(ctxt, h) +} + +// Tasks is a list of Actions that can be used as a single Action. +type Tasks []Action + +// Do executes the list of Tasks using the provided context. +func (t Tasks) Do(ctxt context.Context, h FrameHandler) error { + var err error + + // TODO: put individual task timeouts from context here + for _, a := range t { + // ctxt, cancel = context.WithTimeout(ctxt, timeout) + // defer cancel() + err = a.Do(ctxt, h) + if err != nil { + return err + } + } + + return nil +} + +// Sleep is an empty action that calls time.Sleep with the specified duration. +func Sleep(d time.Duration) Action { + return ActionFunc(func(context.Context, FrameHandler) error { + time.Sleep(d) + return nil + }) +} diff --git a/cdp/accessibility/accessibility.go b/cdp/accessibility/accessibility.go new file mode 100644 index 0000000..ea04fe3 --- /dev/null +++ b/cdp/accessibility/accessibility.go @@ -0,0 +1,111 @@ +// Package accessibility provides the Chrome Debugging Protocol +// commands, types, and events for the Chrome Accessibility domain. +// +// Generated by the chromedp-gen command. +package accessibility + +// AUTOGENERATED. DO NOT EDIT. + +import ( + "context" + + . "github.com/knq/chromedp/cdp" + "github.com/mailru/easyjson" +) + +var ( + _ BackendNode + _ BackendNodeID + _ ComputedProperty + _ ErrorType + _ Frame + _ FrameID + _ LoaderID + _ Message + _ MessageError + _ MethodType + _ Node + _ NodeID + _ NodeType + _ PseudoType + _ RGBA + _ ShadowRootType + _ Timestamp +) + +// GetPartialAXTreeParams fetches the accessibility node and partial +// accessibility tree for this DOM node, if it exists. +type GetPartialAXTreeParams struct { + NodeID NodeID `json:"nodeId"` // ID of node to get the partial accessibility tree for. + FetchRelatives bool `json:"fetchRelatives,omitempty"` // Whether to fetch this nodes ancestors, siblings and children. Defaults to true. +} + +// GetPartialAXTree fetches the accessibility node and partial accessibility +// tree for this DOM node, if it exists. +// +// parameters: +// nodeId - ID of node to get the partial accessibility tree for. +func GetPartialAXTree(nodeId NodeID) *GetPartialAXTreeParams { + return &GetPartialAXTreeParams{ + NodeID: nodeId, + } +} + +// WithFetchRelatives whether to fetch this nodes ancestors, siblings and +// children. Defaults to true. +func (p GetPartialAXTreeParams) WithFetchRelatives(fetchRelatives bool) *GetPartialAXTreeParams { + p.FetchRelatives = fetchRelatives + return &p +} + +// GetPartialAXTreeReturns return values. +type GetPartialAXTreeReturns struct { + Nodes []*AXNode `json:"nodes,omitempty"` // The Accessibility.AXNode for this DOM node, if it exists, plus its ancestors, siblings and children, if requested. +} + +// Do executes Accessibility.getPartialAXTree. +// +// returns: +// nodes - The Accessibility.AXNode for this DOM node, if it exists, plus its ancestors, siblings and children, if requested. +func (p *GetPartialAXTreeParams) Do(ctxt context.Context, h FrameHandler) (nodes []*AXNode, err error) { + if ctxt == nil { + ctxt = context.Background() + } + + // marshal + buf, err := easyjson.Marshal(p) + if err != nil { + return nil, err + } + + // execute + ch := h.Execute(ctxt, CommandAccessibilityGetPartialAXTree, easyjson.RawMessage(buf)) + + // read response + select { + case res := <-ch: + if res == nil { + return nil, ErrChannelClosed + } + + switch v := res.(type) { + case easyjson.RawMessage: + // unmarshal + var r GetPartialAXTreeReturns + err = easyjson.Unmarshal(v, &r) + if err != nil { + return nil, ErrInvalidResult + } + + return r.Nodes, nil + + case error: + return nil, v + } + + case <-ctxt.Done(): + return nil, ErrContextDone + } + + return nil, ErrUnknownResult +} diff --git a/cdp/accessibility/easyjson.go b/cdp/accessibility/easyjson.go new file mode 100644 index 0000000..c43654a --- /dev/null +++ b/cdp/accessibility/easyjson.go @@ -0,0 +1,1064 @@ +// AUTOGENERATED FILE: easyjson marshaler/unmarshalers. + +package accessibility + +import ( + json "encoding/json" + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility(in *jlexer.Lexer, out *GetPartialAXTreeReturns) { + 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 "nodes": + if in.IsNull() { + in.Skip() + out.Nodes = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.Nodes = make([]*AXNode, 0, 8) + } else { + out.Nodes = []*AXNode{} + } + for !in.IsDelim(']') { + var v1 *AXNode + if in.IsNull() { + in.Skip() + v1 = nil + } else { + if v1 == nil { + v1 = new(AXNode) + } + (*v1).UnmarshalEasyJSON(in) + } + out.Nodes = append(out.Nodes, v1) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility(out *jwriter.Writer, in GetPartialAXTreeReturns) { + out.RawByte('{') + first := true + _ = first + if len(in.Nodes) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"nodes\":") + if in.Nodes == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v2, v3 := range in.Nodes { + if v2 > 0 { + out.RawByte(',') + } + if v3 == nil { + out.RawString("null") + } else { + (*v3).MarshalEasyJSON(out) + } + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v GetPartialAXTreeReturns) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v GetPartialAXTreeReturns) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *GetPartialAXTreeReturns) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *GetPartialAXTreeReturns) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility1(in *jlexer.Lexer, out *GetPartialAXTreeParams) { + 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 "nodeId": + (out.NodeID).UnmarshalEasyJSON(in) + case "fetchRelatives": + out.FetchRelatives = bool(in.Bool()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility1(out *jwriter.Writer, in GetPartialAXTreeParams) { + out.RawByte('{') + first := true + _ = first + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"nodeId\":") + out.Int64(int64(in.NodeID)) + if in.FetchRelatives { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"fetchRelatives\":") + out.Bool(bool(in.FetchRelatives)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v GetPartialAXTreeParams) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v GetPartialAXTreeParams) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *GetPartialAXTreeParams) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *GetPartialAXTreeParams) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility1(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility2(in *jlexer.Lexer, out *AXValueSource) { + 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 "type": + (out.Type).UnmarshalEasyJSON(in) + case "value": + if in.IsNull() { + in.Skip() + out.Value = nil + } else { + if out.Value == nil { + out.Value = new(AXValue) + } + (*out.Value).UnmarshalEasyJSON(in) + } + case "attribute": + out.Attribute = string(in.String()) + case "attributeValue": + if in.IsNull() { + in.Skip() + out.AttributeValue = nil + } else { + if out.AttributeValue == nil { + out.AttributeValue = new(AXValue) + } + (*out.AttributeValue).UnmarshalEasyJSON(in) + } + case "superseded": + out.Superseded = bool(in.Bool()) + case "nativeSource": + (out.NativeSource).UnmarshalEasyJSON(in) + case "nativeSourceValue": + if in.IsNull() { + in.Skip() + out.NativeSourceValue = nil + } else { + if out.NativeSourceValue == nil { + out.NativeSourceValue = new(AXValue) + } + (*out.NativeSourceValue).UnmarshalEasyJSON(in) + } + case "invalid": + out.Invalid = bool(in.Bool()) + case "invalidReason": + out.InvalidReason = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility2(out *jwriter.Writer, in AXValueSource) { + out.RawByte('{') + first := true + _ = first + if in.Type != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"type\":") + (in.Type).MarshalEasyJSON(out) + } + if in.Value != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"value\":") + if in.Value == nil { + out.RawString("null") + } else { + (*in.Value).MarshalEasyJSON(out) + } + } + if in.Attribute != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"attribute\":") + out.String(string(in.Attribute)) + } + if in.AttributeValue != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"attributeValue\":") + if in.AttributeValue == nil { + out.RawString("null") + } else { + (*in.AttributeValue).MarshalEasyJSON(out) + } + } + if in.Superseded { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"superseded\":") + out.Bool(bool(in.Superseded)) + } + if in.NativeSource != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"nativeSource\":") + (in.NativeSource).MarshalEasyJSON(out) + } + if in.NativeSourceValue != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"nativeSourceValue\":") + if in.NativeSourceValue == nil { + out.RawString("null") + } else { + (*in.NativeSourceValue).MarshalEasyJSON(out) + } + } + if in.Invalid { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"invalid\":") + out.Bool(bool(in.Invalid)) + } + if in.InvalidReason != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"invalidReason\":") + out.String(string(in.InvalidReason)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v AXValueSource) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility2(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v AXValueSource) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility2(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *AXValueSource) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility2(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *AXValueSource) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility2(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility3(in *jlexer.Lexer, out *AXValue) { + 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 "type": + (out.Type).UnmarshalEasyJSON(in) + case "value": + (out.Value).UnmarshalEasyJSON(in) + case "relatedNodes": + if in.IsNull() { + in.Skip() + out.RelatedNodes = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.RelatedNodes = make([]*AXRelatedNode, 0, 8) + } else { + out.RelatedNodes = []*AXRelatedNode{} + } + for !in.IsDelim(']') { + var v4 *AXRelatedNode + if in.IsNull() { + in.Skip() + v4 = nil + } else { + if v4 == nil { + v4 = new(AXRelatedNode) + } + (*v4).UnmarshalEasyJSON(in) + } + out.RelatedNodes = append(out.RelatedNodes, v4) + in.WantComma() + } + in.Delim(']') + } + case "sources": + if in.IsNull() { + in.Skip() + out.Sources = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.Sources = make([]*AXValueSource, 0, 8) + } else { + out.Sources = []*AXValueSource{} + } + for !in.IsDelim(']') { + var v5 *AXValueSource + if in.IsNull() { + in.Skip() + v5 = nil + } else { + if v5 == nil { + v5 = new(AXValueSource) + } + (*v5).UnmarshalEasyJSON(in) + } + out.Sources = append(out.Sources, v5) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility3(out *jwriter.Writer, in AXValue) { + out.RawByte('{') + first := true + _ = first + if in.Type != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"type\":") + (in.Type).MarshalEasyJSON(out) + } + if (in.Value).IsDefined() { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"value\":") + (in.Value).MarshalEasyJSON(out) + } + if len(in.RelatedNodes) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"relatedNodes\":") + if in.RelatedNodes == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v6, v7 := range in.RelatedNodes { + if v6 > 0 { + out.RawByte(',') + } + if v7 == nil { + out.RawString("null") + } else { + (*v7).MarshalEasyJSON(out) + } + } + out.RawByte(']') + } + } + if len(in.Sources) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"sources\":") + if in.Sources == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v8, v9 := range in.Sources { + if v8 > 0 { + out.RawByte(',') + } + if v9 == nil { + out.RawString("null") + } else { + (*v9).MarshalEasyJSON(out) + } + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v AXValue) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility3(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v AXValue) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility3(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *AXValue) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility3(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *AXValue) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility3(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility4(in *jlexer.Lexer, out *AXRelatedNode) { + 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 "backendDOMNodeId": + (out.BackendDOMNodeID).UnmarshalEasyJSON(in) + case "idref": + out.Idref = string(in.String()) + case "text": + out.Text = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility4(out *jwriter.Writer, in AXRelatedNode) { + out.RawByte('{') + first := true + _ = first + if in.BackendDOMNodeID != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"backendDOMNodeId\":") + out.Int64(int64(in.BackendDOMNodeID)) + } + if in.Idref != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"idref\":") + out.String(string(in.Idref)) + } + if in.Text != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"text\":") + out.String(string(in.Text)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v AXRelatedNode) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility4(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v AXRelatedNode) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility4(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *AXRelatedNode) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility4(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *AXRelatedNode) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility4(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility5(in *jlexer.Lexer, out *AXProperty) { + 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 "name": + out.Name = string(in.String()) + case "value": + if in.IsNull() { + in.Skip() + out.Value = nil + } else { + if out.Value == nil { + out.Value = new(AXValue) + } + (*out.Value).UnmarshalEasyJSON(in) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility5(out *jwriter.Writer, in AXProperty) { + out.RawByte('{') + first := true + _ = first + if in.Name != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"name\":") + out.String(string(in.Name)) + } + if in.Value != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"value\":") + if in.Value == nil { + out.RawString("null") + } else { + (*in.Value).MarshalEasyJSON(out) + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v AXProperty) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility5(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v AXProperty) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility5(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *AXProperty) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility5(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *AXProperty) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility5(l, v) +} +func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility6(in *jlexer.Lexer, out *AXNode) { + 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 "nodeId": + out.NodeID = AXNodeID(in.String()) + case "ignored": + out.Ignored = bool(in.Bool()) + case "ignoredReasons": + if in.IsNull() { + in.Skip() + out.IgnoredReasons = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.IgnoredReasons = make([]*AXProperty, 0, 8) + } else { + out.IgnoredReasons = []*AXProperty{} + } + for !in.IsDelim(']') { + var v10 *AXProperty + if in.IsNull() { + in.Skip() + v10 = nil + } else { + if v10 == nil { + v10 = new(AXProperty) + } + (*v10).UnmarshalEasyJSON(in) + } + out.IgnoredReasons = append(out.IgnoredReasons, v10) + in.WantComma() + } + in.Delim(']') + } + case "role": + if in.IsNull() { + in.Skip() + out.Role = nil + } else { + if out.Role == nil { + out.Role = new(AXValue) + } + (*out.Role).UnmarshalEasyJSON(in) + } + case "name": + if in.IsNull() { + in.Skip() + out.Name = nil + } else { + if out.Name == nil { + out.Name = new(AXValue) + } + (*out.Name).UnmarshalEasyJSON(in) + } + case "description": + if in.IsNull() { + in.Skip() + out.Description = nil + } else { + if out.Description == nil { + out.Description = new(AXValue) + } + (*out.Description).UnmarshalEasyJSON(in) + } + case "value": + if in.IsNull() { + in.Skip() + out.Value = nil + } else { + if out.Value == nil { + out.Value = new(AXValue) + } + (*out.Value).UnmarshalEasyJSON(in) + } + case "properties": + if in.IsNull() { + in.Skip() + out.Properties = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.Properties = make([]*AXProperty, 0, 8) + } else { + out.Properties = []*AXProperty{} + } + for !in.IsDelim(']') { + var v11 *AXProperty + if in.IsNull() { + in.Skip() + v11 = nil + } else { + if v11 == nil { + v11 = new(AXProperty) + } + (*v11).UnmarshalEasyJSON(in) + } + out.Properties = append(out.Properties, v11) + in.WantComma() + } + in.Delim(']') + } + case "childIds": + if in.IsNull() { + in.Skip() + out.ChildIds = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.ChildIds = make([]AXNodeID, 0, 4) + } else { + out.ChildIds = []AXNodeID{} + } + for !in.IsDelim(']') { + var v12 AXNodeID + v12 = AXNodeID(in.String()) + out.ChildIds = append(out.ChildIds, v12) + in.WantComma() + } + in.Delim(']') + } + case "backendDOMNodeId": + (out.BackendDOMNodeID).UnmarshalEasyJSON(in) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility6(out *jwriter.Writer, in AXNode) { + out.RawByte('{') + first := true + _ = first + if in.NodeID != "" { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"nodeId\":") + out.String(string(in.NodeID)) + } + if in.Ignored { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"ignored\":") + out.Bool(bool(in.Ignored)) + } + if len(in.IgnoredReasons) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"ignoredReasons\":") + if in.IgnoredReasons == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v13, v14 := range in.IgnoredReasons { + if v13 > 0 { + out.RawByte(',') + } + if v14 == nil { + out.RawString("null") + } else { + (*v14).MarshalEasyJSON(out) + } + } + out.RawByte(']') + } + } + if in.Role != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"role\":") + if in.Role == nil { + out.RawString("null") + } else { + (*in.Role).MarshalEasyJSON(out) + } + } + if in.Name != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"name\":") + if in.Name == nil { + out.RawString("null") + } else { + (*in.Name).MarshalEasyJSON(out) + } + } + if in.Description != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"description\":") + if in.Description == nil { + out.RawString("null") + } else { + (*in.Description).MarshalEasyJSON(out) + } + } + if in.Value != nil { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"value\":") + if in.Value == nil { + out.RawString("null") + } else { + (*in.Value).MarshalEasyJSON(out) + } + } + if len(in.Properties) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"properties\":") + if in.Properties == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v15, v16 := range in.Properties { + if v15 > 0 { + out.RawByte(',') + } + if v16 == nil { + out.RawString("null") + } else { + (*v16).MarshalEasyJSON(out) + } + } + out.RawByte(']') + } + } + if len(in.ChildIds) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"childIds\":") + if in.ChildIds == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v17, v18 := range in.ChildIds { + if v17 > 0 { + out.RawByte(',') + } + out.String(string(v18)) + } + out.RawByte(']') + } + } + if in.BackendDOMNodeID != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"backendDOMNodeId\":") + out.Int64(int64(in.BackendDOMNodeID)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v AXNode) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility6(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v AXNode) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonC5a4559bEncodeGithubComKnqChromedpCdpAccessibility6(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *AXNode) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility6(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *AXNode) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonC5a4559bDecodeGithubComKnqChromedpCdpAccessibility6(l, v) +} diff --git a/cdp/accessibility/types.go b/cdp/accessibility/types.go new file mode 100644 index 0000000..471e14b --- /dev/null +++ b/cdp/accessibility/types.go @@ -0,0 +1,559 @@ +package accessibility + +// AUTOGENERATED. DO NOT EDIT. + +import ( + "errors" + + . "github.com/knq/chromedp/cdp" + "github.com/mailru/easyjson" + "github.com/mailru/easyjson/jlexer" + "github.com/mailru/easyjson/jwriter" +) + +var ( + _ BackendNode + _ BackendNodeID + _ ComputedProperty + _ ErrorType + _ Frame + _ FrameID + _ LoaderID + _ Message + _ MessageError + _ MethodType + _ Node + _ NodeID + _ NodeType + _ PseudoType + _ RGBA + _ ShadowRootType + _ Timestamp +) + +// AXNodeID unique accessibility node identifier. +type AXNodeID string + +// String returns the AXNodeID as string value. +func (t AXNodeID) String() string { + return string(t) +} + +// AXValueType enum of possible property types. +type AXValueType string + +// String returns the AXValueType as string value. +func (t AXValueType) String() string { + return string(t) +} + +// AXValueType values. +const ( + AXValueTypeBoolean AXValueType = "boolean" + AXValueTypeTristate AXValueType = "tristate" + AXValueTypeBooleanOrUndefined AXValueType = "booleanOrUndefined" + AXValueTypeIdref AXValueType = "idref" + AXValueTypeIdrefList AXValueType = "idrefList" + AXValueTypeInteger AXValueType = "integer" + AXValueTypeNode AXValueType = "node" + AXValueTypeNodeList AXValueType = "nodeList" + AXValueTypeNumber AXValueType = "number" + AXValueTypeString AXValueType = "string" + AXValueTypeComputedString AXValueType = "computedString" + AXValueTypeToken AXValueType = "token" + AXValueTypeTokenList AXValueType = "tokenList" + AXValueTypeDomRelation AXValueType = "domRelation" + AXValueTypeRole AXValueType = "role" + AXValueTypeInternalRole AXValueType = "internalRole" + AXValueTypeValueUndefined AXValueType = "valueUndefined" +) + +// MarshalEasyJSON satisfies easyjson.Marshaler. +func (t AXValueType) MarshalEasyJSON(out *jwriter.Writer) { + out.String(string(t)) +} + +// MarshalJSON satisfies json.Marshaler. +func (t AXValueType) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *AXValueType) UnmarshalEasyJSON(in *jlexer.Lexer) { + switch AXValueType(in.String()) { + case AXValueTypeBoolean: + *t = AXValueTypeBoolean + case AXValueTypeTristate: + *t = AXValueTypeTristate + case AXValueTypeBooleanOrUndefined: + *t = AXValueTypeBooleanOrUndefined + case AXValueTypeIdref: + *t = AXValueTypeIdref + case AXValueTypeIdrefList: + *t = AXValueTypeIdrefList + case AXValueTypeInteger: + *t = AXValueTypeInteger + case AXValueTypeNode: + *t = AXValueTypeNode + case AXValueTypeNodeList: + *t = AXValueTypeNodeList + case AXValueTypeNumber: + *t = AXValueTypeNumber + case AXValueTypeString: + *t = AXValueTypeString + case AXValueTypeComputedString: + *t = AXValueTypeComputedString + case AXValueTypeToken: + *t = AXValueTypeToken + case AXValueTypeTokenList: + *t = AXValueTypeTokenList + case AXValueTypeDomRelation: + *t = AXValueTypeDomRelation + case AXValueTypeRole: + *t = AXValueTypeRole + case AXValueTypeInternalRole: + *t = AXValueTypeInternalRole + case AXValueTypeValueUndefined: + *t = AXValueTypeValueUndefined + + default: + in.AddError(errors.New("unknown AXValueType value")) + } +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *AXValueType) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +} + +// AXValueSourceType enum of possible property sources. +type AXValueSourceType string + +// String returns the AXValueSourceType as string value. +func (t AXValueSourceType) String() string { + return string(t) +} + +// AXValueSourceType values. +const ( + AXValueSourceTypeAttribute AXValueSourceType = "attribute" + AXValueSourceTypeImplicit AXValueSourceType = "implicit" + AXValueSourceTypeStyle AXValueSourceType = "style" + AXValueSourceTypeContents AXValueSourceType = "contents" + AXValueSourceTypePlaceholder AXValueSourceType = "placeholder" + AXValueSourceTypeRelatedElement AXValueSourceType = "relatedElement" +) + +// MarshalEasyJSON satisfies easyjson.Marshaler. +func (t AXValueSourceType) MarshalEasyJSON(out *jwriter.Writer) { + out.String(string(t)) +} + +// MarshalJSON satisfies json.Marshaler. +func (t AXValueSourceType) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *AXValueSourceType) UnmarshalEasyJSON(in *jlexer.Lexer) { + switch AXValueSourceType(in.String()) { + case AXValueSourceTypeAttribute: + *t = AXValueSourceTypeAttribute + case AXValueSourceTypeImplicit: + *t = AXValueSourceTypeImplicit + case AXValueSourceTypeStyle: + *t = AXValueSourceTypeStyle + case AXValueSourceTypeContents: + *t = AXValueSourceTypeContents + case AXValueSourceTypePlaceholder: + *t = AXValueSourceTypePlaceholder + case AXValueSourceTypeRelatedElement: + *t = AXValueSourceTypeRelatedElement + + default: + in.AddError(errors.New("unknown AXValueSourceType value")) + } +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *AXValueSourceType) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +} + +// AXValueNativeSourceType enum of possible native property sources (as a +// subtype of a particular AXValueSourceType). +type AXValueNativeSourceType string + +// String returns the AXValueNativeSourceType as string value. +func (t AXValueNativeSourceType) String() string { + return string(t) +} + +// AXValueNativeSourceType values. +const ( + AXValueNativeSourceTypeFigcaption AXValueNativeSourceType = "figcaption" + AXValueNativeSourceTypeLabel AXValueNativeSourceType = "label" + AXValueNativeSourceTypeLabelfor AXValueNativeSourceType = "labelfor" + AXValueNativeSourceTypeLabelwrapped AXValueNativeSourceType = "labelwrapped" + AXValueNativeSourceTypeLegend AXValueNativeSourceType = "legend" + AXValueNativeSourceTypeTablecaption AXValueNativeSourceType = "tablecaption" + AXValueNativeSourceTypeTitle AXValueNativeSourceType = "title" + AXValueNativeSourceTypeOther AXValueNativeSourceType = "other" +) + +// MarshalEasyJSON satisfies easyjson.Marshaler. +func (t AXValueNativeSourceType) MarshalEasyJSON(out *jwriter.Writer) { + out.String(string(t)) +} + +// MarshalJSON satisfies json.Marshaler. +func (t AXValueNativeSourceType) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *AXValueNativeSourceType) UnmarshalEasyJSON(in *jlexer.Lexer) { + switch AXValueNativeSourceType(in.String()) { + case AXValueNativeSourceTypeFigcaption: + *t = AXValueNativeSourceTypeFigcaption + case AXValueNativeSourceTypeLabel: + *t = AXValueNativeSourceTypeLabel + case AXValueNativeSourceTypeLabelfor: + *t = AXValueNativeSourceTypeLabelfor + case AXValueNativeSourceTypeLabelwrapped: + *t = AXValueNativeSourceTypeLabelwrapped + case AXValueNativeSourceTypeLegend: + *t = AXValueNativeSourceTypeLegend + case AXValueNativeSourceTypeTablecaption: + *t = AXValueNativeSourceTypeTablecaption + case AXValueNativeSourceTypeTitle: + *t = AXValueNativeSourceTypeTitle + case AXValueNativeSourceTypeOther: + *t = AXValueNativeSourceTypeOther + + default: + in.AddError(errors.New("unknown AXValueNativeSourceType value")) + } +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *AXValueNativeSourceType) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +} + +// AXValueSource a single source for a computed AX property. +type AXValueSource struct { + Type AXValueSourceType `json:"type,omitempty"` // What type of source this is. + Value *AXValue `json:"value,omitempty"` // The value of this property source. + Attribute string `json:"attribute,omitempty"` // The name of the relevant attribute, if any. + AttributeValue *AXValue `json:"attributeValue,omitempty"` // The value of the relevant attribute, if any. + Superseded bool `json:"superseded,omitempty"` // Whether this source is superseded by a higher priority source. + NativeSource AXValueNativeSourceType `json:"nativeSource,omitempty"` // The native markup source for this value, e.g. a