package cdp
import (
"context"
"fmt"
"strconv"
"strings"
"sync"
"time"
"github.com/chromedp/sysutil"
"github.com/mailru/easyjson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
type Executor interface {
Execute (context .Context , string , easyjson .Marshaler , easyjson .Unmarshaler ) error
}
type contextKey int
const (
executorKey contextKey = iota
)
func WithExecutor (parent context .Context , executor Executor ) context .Context {
return context .WithValue (parent , executorKey , executor )
}
func ExecutorFromContext (ctx context .Context ) Executor {
return ctx .Value (executorKey ).(Executor )
}
func Execute (ctx context .Context , method string , params easyjson .Marshaler , res easyjson .Unmarshaler ) error {
if executor := ctx .Value (executorKey ); executor != nil {
return executor .(Executor ).Execute (ctx , method , params , res )
}
return ErrInvalidContext
}
type Error string
const (
ErrInvalidContext Error = "invalid context"
ErrMsgMissingParamsOrResult Error = "msg missing params or result"
)
func (err Error ) Error () string {
return string (err )
}
type ErrUnknownCommandOrEvent string
func (err ErrUnknownCommandOrEvent ) Error () string {
return fmt .Sprintf ("unknown command or event %q" , string (err ))
}
type BrowserContextID string
func (t BrowserContextID ) String () string {
return string (t )
}
type NodeID int64
func (t NodeID ) Int64 () int64 {
return int64 (t )
}
func (t *NodeID ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
buf := in .Raw ()
if l := len (buf ); l > 2 && buf [0 ] == '"' && buf [l -1 ] == '"' {
buf = buf [1 : l -1 ]
}
v , err := strconv .ParseInt (string (buf ), 10 , 64 )
if err != nil {
in .AddError (err )
}
*t = NodeID (v )
}
func (t *NodeID ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type BackendNodeID int64
func (t BackendNodeID ) Int64 () int64 {
return int64 (t )
}
func (t *BackendNodeID ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
buf := in .Raw ()
if l := len (buf ); l > 2 && buf [0 ] == '"' && buf [l -1 ] == '"' {
buf = buf [1 : l -1 ]
}
v , err := strconv .ParseInt (string (buf ), 10 , 64 )
if err != nil {
in .AddError (err )
}
*t = BackendNodeID (v )
}
func (t *BackendNodeID ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type BackendNode struct {
NodeType NodeType `json:"nodeType"`
NodeName string `json:"nodeName"`
BackendNodeID BackendNodeID `json:"backendNodeId"`
}
type PseudoType string
func (t PseudoType ) String () string {
return string (t )
}
const (
PseudoTypeFirstLine PseudoType = "first-line"
PseudoTypeFirstLetter PseudoType = "first-letter"
PseudoTypeBefore PseudoType = "before"
PseudoTypeAfter PseudoType = "after"
PseudoTypeMarker PseudoType = "marker"
PseudoTypeBackdrop PseudoType = "backdrop"
PseudoTypeSelection PseudoType = "selection"
PseudoTypeTargetText PseudoType = "target-text"
PseudoTypeSpellingError PseudoType = "spelling-error"
PseudoTypeGrammarError PseudoType = "grammar-error"
PseudoTypeHighlight PseudoType = "highlight"
PseudoTypeFirstLineInherited PseudoType = "first-line-inherited"
PseudoTypeScrollbar PseudoType = "scrollbar"
PseudoTypeScrollbarThumb PseudoType = "scrollbar-thumb"
PseudoTypeScrollbarButton PseudoType = "scrollbar-button"
PseudoTypeScrollbarTrack PseudoType = "scrollbar-track"
PseudoTypeScrollbarTrackPiece PseudoType = "scrollbar-track-piece"
PseudoTypeScrollbarCorner PseudoType = "scrollbar-corner"
PseudoTypeResizer PseudoType = "resizer"
PseudoTypeInputListButton PseudoType = "input-list-button"
PseudoTypeViewTransition PseudoType = "view-transition"
PseudoTypeViewTransitionGroup PseudoType = "view-transition-group"
PseudoTypeViewTransitionImagePair PseudoType = "view-transition-image-pair"
PseudoTypeViewTransitionOld PseudoType = "view-transition-old"
PseudoTypeViewTransitionNew PseudoType = "view-transition-new"
)
func (t PseudoType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t PseudoType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *PseudoType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch PseudoType (v ) {
case PseudoTypeFirstLine :
*t = PseudoTypeFirstLine
case PseudoTypeFirstLetter :
*t = PseudoTypeFirstLetter
case PseudoTypeBefore :
*t = PseudoTypeBefore
case PseudoTypeAfter :
*t = PseudoTypeAfter
case PseudoTypeMarker :
*t = PseudoTypeMarker
case PseudoTypeBackdrop :
*t = PseudoTypeBackdrop
case PseudoTypeSelection :
*t = PseudoTypeSelection
case PseudoTypeTargetText :
*t = PseudoTypeTargetText
case PseudoTypeSpellingError :
*t = PseudoTypeSpellingError
case PseudoTypeGrammarError :
*t = PseudoTypeGrammarError
case PseudoTypeHighlight :
*t = PseudoTypeHighlight
case PseudoTypeFirstLineInherited :
*t = PseudoTypeFirstLineInherited
case PseudoTypeScrollbar :
*t = PseudoTypeScrollbar
case PseudoTypeScrollbarThumb :
*t = PseudoTypeScrollbarThumb
case PseudoTypeScrollbarButton :
*t = PseudoTypeScrollbarButton
case PseudoTypeScrollbarTrack :
*t = PseudoTypeScrollbarTrack
case PseudoTypeScrollbarTrackPiece :
*t = PseudoTypeScrollbarTrackPiece
case PseudoTypeScrollbarCorner :
*t = PseudoTypeScrollbarCorner
case PseudoTypeResizer :
*t = PseudoTypeResizer
case PseudoTypeInputListButton :
*t = PseudoTypeInputListButton
case PseudoTypeViewTransition :
*t = PseudoTypeViewTransition
case PseudoTypeViewTransitionGroup :
*t = PseudoTypeViewTransitionGroup
case PseudoTypeViewTransitionImagePair :
*t = PseudoTypeViewTransitionImagePair
case PseudoTypeViewTransitionOld :
*t = PseudoTypeViewTransitionOld
case PseudoTypeViewTransitionNew :
*t = PseudoTypeViewTransitionNew
default :
in .AddError (fmt .Errorf ("unknown PseudoType value: %v" , v ))
}
}
func (t *PseudoType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type ShadowRootType string
func (t ShadowRootType ) String () string {
return string (t )
}
const (
ShadowRootTypeUserAgent ShadowRootType = "user-agent"
ShadowRootTypeOpen ShadowRootType = "open"
ShadowRootTypeClosed ShadowRootType = "closed"
)
func (t ShadowRootType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t ShadowRootType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *ShadowRootType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch ShadowRootType (v ) {
case ShadowRootTypeUserAgent :
*t = ShadowRootTypeUserAgent
case ShadowRootTypeOpen :
*t = ShadowRootTypeOpen
case ShadowRootTypeClosed :
*t = ShadowRootTypeClosed
default :
in .AddError (fmt .Errorf ("unknown ShadowRootType value: %v" , v ))
}
}
func (t *ShadowRootType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type CompatibilityMode string
func (t CompatibilityMode ) String () string {
return string (t )
}
const (
CompatibilityModeQuirksMode CompatibilityMode = "QuirksMode"
CompatibilityModeLimitedQuirksMode CompatibilityMode = "LimitedQuirksMode"
CompatibilityModeNoQuirksMode CompatibilityMode = "NoQuirksMode"
)
func (t CompatibilityMode ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t CompatibilityMode ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *CompatibilityMode ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch CompatibilityMode (v ) {
case CompatibilityModeQuirksMode :
*t = CompatibilityModeQuirksMode
case CompatibilityModeLimitedQuirksMode :
*t = CompatibilityModeLimitedQuirksMode
case CompatibilityModeNoQuirksMode :
*t = CompatibilityModeNoQuirksMode
default :
in .AddError (fmt .Errorf ("unknown CompatibilityMode value: %v" , v ))
}
}
func (t *CompatibilityMode ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type Node struct {
NodeID NodeID `json:"nodeId"`
ParentID NodeID `json:"parentId,omitempty"`
BackendNodeID BackendNodeID `json:"backendNodeId"`
NodeType NodeType `json:"nodeType"`
NodeName string `json:"nodeName"`
LocalName string `json:"localName"`
NodeValue string `json:"nodeValue"`
ChildNodeCount int64 `json:"childNodeCount,omitempty"`
Children []*Node `json:"children,omitempty"`
Attributes []string `json:"attributes,omitempty"`
DocumentURL string `json:"documentURL,omitempty"`
BaseURL string `json:"baseURL,omitempty"`
PublicID string `json:"publicId,omitempty"`
SystemID string `json:"systemId,omitempty"`
InternalSubset string `json:"internalSubset,omitempty"`
XMLVersion string `json:"xmlVersion,omitempty"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
PseudoType PseudoType `json:"pseudoType,omitempty"`
PseudoIdentifier string `json:"pseudoIdentifier,omitempty"`
ShadowRootType ShadowRootType `json:"shadowRootType,omitempty"`
FrameID FrameID `json:"frameId,omitempty"`
ContentDocument *Node `json:"contentDocument,omitempty"`
ShadowRoots []*Node `json:"shadowRoots,omitempty"`
TemplateContent *Node `json:"templateContent,omitempty"`
PseudoElements []*Node `json:"pseudoElements,omitempty"`
DistributedNodes []*BackendNode `json:"distributedNodes,omitempty"`
IsSVG bool `json:"isSVG,omitempty"`
CompatibilityMode CompatibilityMode `json:"compatibilityMode,omitempty"`
AssignedSlot *BackendNode `json:"assignedSlot,omitempty"`
Parent *Node `json:"-"`
Invalidated chan struct {} `json:"-"`
State NodeState `json:"-"`
sync .RWMutex `json:"-"`
}
func (n *Node ) AttributeValue (name string ) string {
value , _ := n .Attribute (name )
return value
}
func (n *Node ) Attribute (name string ) (string , bool ) {
n .RLock ()
defer n .RUnlock ()
for i := 0 ; i < len (n .Attributes ); i += 2 {
if n .Attributes [i ] == name {
return n .Attributes [i +1 ], true
}
}
return "" , false
}
func (n *Node ) xpath (stopAtDocument , stopAtID bool ) string {
n .RLock ()
defer n .RUnlock ()
p , pos , id := "" , "" , n .AttributeValue ("id" )
switch {
case n .Parent == nil :
return n .LocalName
case stopAtDocument && n .NodeType == NodeTypeDocument :
return ""
case stopAtID && id != "" :
p = "/"
pos = `[@id='` + id + `']`
case n .Parent != nil :
var i int
var found bool
n .Parent .RLock ()
for j := 0 ; j < len (n .Parent .Children ); j ++ {
if n .Parent .Children [j ].LocalName == n .LocalName {
i ++
}
if n .Parent .Children [j ].NodeID == n .NodeID {
found = true
break
}
}
n .Parent .RUnlock ()
if found {
pos = "[" + strconv .Itoa (i ) + "]"
}
p = n .Parent .xpath (stopAtDocument , stopAtID )
}
localName := n .LocalName
if n .IsSVG {
localName = `*[local-name()='` + localName + `']`
}
return p + "/" + localName + pos
}
func (n *Node ) PartialXPathByID () string {
return n .xpath (true , true )
}
func (n *Node ) PartialXPath () string {
return n .xpath (true , false )
}
func (n *Node ) FullXPathByID () string {
return n .xpath (false , true )
}
func (n *Node ) FullXPath () string {
return n .xpath (false , false )
}
func (n *Node ) Dump (prefix , indent string , nodeIDs bool ) string {
if n == nil {
return prefix + "<nil>"
}
n .RLock ()
defer n .RUnlock ()
s := n .LocalName
if s == "" {
s = n .NodeName
}
for i := 0 ; i < len (n .Attributes ); i += 2 {
if strings .ToLower (n .Attributes [i ]) == "id" {
s += "#" + n .Attributes [i +1 ]
break
}
}
if n .NodeType != NodeTypeElement && n .NodeType != NodeTypeText {
s += fmt .Sprintf (" <%s>" , n .NodeType )
}
if n .NodeType == NodeTypeText {
v := n .NodeValue
if len (v ) > 15 {
v = v [:15 ] + "..."
}
s += fmt .Sprintf (" %q" , v )
}
if n .NodeType == NodeTypeElement && len (n .Attributes ) > 0 {
attrs := ""
for i := 0 ; i < len (n .Attributes ); i += 2 {
if strings .ToLower (n .Attributes [i ]) == "id" {
continue
}
if attrs != "" {
attrs += " "
}
attrs += fmt .Sprintf ("%s=%q" , n .Attributes [i ], n .Attributes [i +1 ])
}
if attrs != "" {
s += " [" + attrs + "]"
}
}
if nodeIDs {
s += fmt .Sprintf (" (%d)" , n .NodeID )
}
for i := 0 ; i < len (n .Children ); i ++ {
s += "\n" + n .Children [i ].Dump (prefix +indent , indent , nodeIDs )
}
return prefix + s
}
type NodeState uint8
const (
NodeReady NodeState = 1 << (7 - iota )
NodeVisible
NodeHighlighted
)
var nodeStateNames = map [NodeState ]string {
NodeReady : "Ready" ,
NodeVisible : "Visible" ,
NodeHighlighted : "Highlighted" ,
}
func (ns NodeState ) String () string {
var s []string
for k , v := range nodeStateNames {
if ns &k != 0 {
s = append (s , v )
}
}
return "[" + strings .Join (s , " " ) + "]"
}
const EmptyNodeID = NodeID (0 )
type RGBA struct {
R int64 `json:"r"`
G int64 `json:"g"`
B int64 `json:"b"`
A float64 `json:"a"`
}
type NodeType int64
func (t NodeType ) Int64 () int64 {
return int64 (t )
}
const (
NodeTypeElement NodeType = 1
NodeTypeAttribute NodeType = 2
NodeTypeText NodeType = 3
NodeTypeCDATA NodeType = 4
NodeTypeEntityReference NodeType = 5
NodeTypeEntity NodeType = 6
NodeTypeProcessingInstruction NodeType = 7
NodeTypeComment NodeType = 8
NodeTypeDocument NodeType = 9
NodeTypeDocumentType NodeType = 10
NodeTypeDocumentFragment NodeType = 11
NodeTypeNotation NodeType = 12
)
func (t NodeType ) String () string {
switch t {
case NodeTypeElement :
return "Element"
case NodeTypeAttribute :
return "Attribute"
case NodeTypeText :
return "Text"
case NodeTypeCDATA :
return "CDATA"
case NodeTypeEntityReference :
return "EntityReference"
case NodeTypeEntity :
return "Entity"
case NodeTypeProcessingInstruction :
return "ProcessingInstruction"
case NodeTypeComment :
return "Comment"
case NodeTypeDocument :
return "Document"
case NodeTypeDocumentType :
return "DocumentType"
case NodeTypeDocumentFragment :
return "DocumentFragment"
case NodeTypeNotation :
return "Notation"
}
return fmt .Sprintf ("NodeType(%d)" , t )
}
func (t NodeType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .Int64 (int64 (t ))
}
func (t NodeType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *NodeType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .Int64 ()
switch NodeType (v ) {
case NodeTypeElement :
*t = NodeTypeElement
case NodeTypeAttribute :
*t = NodeTypeAttribute
case NodeTypeText :
*t = NodeTypeText
case NodeTypeCDATA :
*t = NodeTypeCDATA
case NodeTypeEntityReference :
*t = NodeTypeEntityReference
case NodeTypeEntity :
*t = NodeTypeEntity
case NodeTypeProcessingInstruction :
*t = NodeTypeProcessingInstruction
case NodeTypeComment :
*t = NodeTypeComment
case NodeTypeDocument :
*t = NodeTypeDocument
case NodeTypeDocumentType :
*t = NodeTypeDocumentType
case NodeTypeDocumentFragment :
*t = NodeTypeDocumentFragment
case NodeTypeNotation :
*t = NodeTypeNotation
default :
in .AddError (fmt .Errorf ("unknown NodeType value: %v" , v ))
}
}
func (t *NodeType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type LoaderID string
func (t LoaderID ) String () string {
return string (t )
}
type TimeSinceEpoch time .Time
func (t TimeSinceEpoch ) Time () time .Time {
return time .Time (t )
}
func (t TimeSinceEpoch ) MarshalEasyJSON (out *jwriter .Writer ) {
v := float64 (time .Time (t ).UnixNano () / int64 (time .Second ))
out .Buffer .EnsureSpace (20 )
out .Buffer .Buf = strconv .AppendFloat (out .Buffer .Buf , v , 'f' , -1 , 64 )
}
func (t TimeSinceEpoch ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *TimeSinceEpoch ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
*t = TimeSinceEpoch (time .Unix (0 , int64 (in .Float64 ()*float64 (time .Second ))))
}
func (t *TimeSinceEpoch ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type MonotonicTime time .Time
func (t MonotonicTime ) Time () time .Time {
return time .Time (t )
}
var MonotonicTimeEpoch *time .Time
func init() {
bt := sysutil .BootTime ()
MonotonicTimeEpoch = &bt
}
func (t MonotonicTime ) MarshalEasyJSON (out *jwriter .Writer ) {
v := float64 (time .Time (t ).Sub (*MonotonicTimeEpoch )) / float64 (time .Second )
out .Buffer .EnsureSpace (20 )
out .Buffer .Buf = strconv .AppendFloat (out .Buffer .Buf , v , 'f' , -1 , 64 )
}
func (t MonotonicTime ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *MonotonicTime ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
*t = MonotonicTime (MonotonicTimeEpoch .Add (time .Duration (in .Float64 () * float64 (time .Second ))))
}
func (t *MonotonicTime ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type TimeSinceEpochMilli time .Time
func (t TimeSinceEpochMilli ) Time () time .Time {
return time .Time (t )
}
func (t TimeSinceEpochMilli ) MarshalEasyJSON (out *jwriter .Writer ) {
v := float64 (time .Time (t ).UnixNano () / int64 (time .Millisecond ))
out .Buffer .EnsureSpace (20 )
out .Buffer .Buf = strconv .AppendFloat (out .Buffer .Buf , v , 'f' , -1 , 64 )
}
func (t TimeSinceEpochMilli ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *TimeSinceEpochMilli ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
*t = TimeSinceEpochMilli (time .Unix (0 , int64 (in .Float64 ()*float64 (time .Millisecond ))))
}
func (t *TimeSinceEpochMilli ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type FrameID string
func (t FrameID ) String () string {
return string (t )
}
func (t *FrameID ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
buf := in .Raw ()
if l := len (buf ); l > 2 && buf [0 ] == '"' && buf [l -1 ] == '"' {
buf = buf [1 : l -1 ]
}
*t = FrameID (buf )
}
func (t *FrameID ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type AdFrameType string
func (t AdFrameType ) String () string {
return string (t )
}
const (
AdFrameTypeNone AdFrameType = "none"
AdFrameTypeChild AdFrameType = "child"
AdFrameTypeRoot AdFrameType = "root"
)
func (t AdFrameType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t AdFrameType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *AdFrameType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch AdFrameType (v ) {
case AdFrameTypeNone :
*t = AdFrameTypeNone
case AdFrameTypeChild :
*t = AdFrameTypeChild
case AdFrameTypeRoot :
*t = AdFrameTypeRoot
default :
in .AddError (fmt .Errorf ("unknown AdFrameType value: %v" , v ))
}
}
func (t *AdFrameType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type AdFrameExplanation string
func (t AdFrameExplanation ) String () string {
return string (t )
}
const (
AdFrameExplanationParentIsAd AdFrameExplanation = "ParentIsAd"
AdFrameExplanationCreatedByAdScript AdFrameExplanation = "CreatedByAdScript"
AdFrameExplanationMatchedBlockingRule AdFrameExplanation = "MatchedBlockingRule"
)
func (t AdFrameExplanation ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t AdFrameExplanation ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *AdFrameExplanation ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch AdFrameExplanation (v ) {
case AdFrameExplanationParentIsAd :
*t = AdFrameExplanationParentIsAd
case AdFrameExplanationCreatedByAdScript :
*t = AdFrameExplanationCreatedByAdScript
case AdFrameExplanationMatchedBlockingRule :
*t = AdFrameExplanationMatchedBlockingRule
default :
in .AddError (fmt .Errorf ("unknown AdFrameExplanation value: %v" , v ))
}
}
func (t *AdFrameExplanation ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type AdFrameStatus struct {
AdFrameType AdFrameType `json:"adFrameType"`
Explanations []AdFrameExplanation `json:"explanations,omitempty"`
}
type SecureContextType string
func (t SecureContextType ) String () string {
return string (t )
}
const (
SecureContextTypeSecure SecureContextType = "Secure"
SecureContextTypeSecureLocalhost SecureContextType = "SecureLocalhost"
SecureContextTypeInsecureScheme SecureContextType = "InsecureScheme"
SecureContextTypeInsecureAncestor SecureContextType = "InsecureAncestor"
)
func (t SecureContextType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t SecureContextType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *SecureContextType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch SecureContextType (v ) {
case SecureContextTypeSecure :
*t = SecureContextTypeSecure
case SecureContextTypeSecureLocalhost :
*t = SecureContextTypeSecureLocalhost
case SecureContextTypeInsecureScheme :
*t = SecureContextTypeInsecureScheme
case SecureContextTypeInsecureAncestor :
*t = SecureContextTypeInsecureAncestor
default :
in .AddError (fmt .Errorf ("unknown SecureContextType value: %v" , v ))
}
}
func (t *SecureContextType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type CrossOriginIsolatedContextType string
func (t CrossOriginIsolatedContextType ) String () string {
return string (t )
}
const (
CrossOriginIsolatedContextTypeIsolated CrossOriginIsolatedContextType = "Isolated"
CrossOriginIsolatedContextTypeNotIsolated CrossOriginIsolatedContextType = "NotIsolated"
CrossOriginIsolatedContextTypeNotIsolatedFeatureDisabled CrossOriginIsolatedContextType = "NotIsolatedFeatureDisabled"
)
func (t CrossOriginIsolatedContextType ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t CrossOriginIsolatedContextType ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *CrossOriginIsolatedContextType ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch CrossOriginIsolatedContextType (v ) {
case CrossOriginIsolatedContextTypeIsolated :
*t = CrossOriginIsolatedContextTypeIsolated
case CrossOriginIsolatedContextTypeNotIsolated :
*t = CrossOriginIsolatedContextTypeNotIsolated
case CrossOriginIsolatedContextTypeNotIsolatedFeatureDisabled :
*t = CrossOriginIsolatedContextTypeNotIsolatedFeatureDisabled
default :
in .AddError (fmt .Errorf ("unknown CrossOriginIsolatedContextType value: %v" , v ))
}
}
func (t *CrossOriginIsolatedContextType ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type GatedAPIFeatures string
func (t GatedAPIFeatures ) String () string {
return string (t )
}
const (
GatedAPIFeaturesSharedArrayBuffers GatedAPIFeatures = "SharedArrayBuffers"
GatedAPIFeaturesSharedArrayBuffersTransferAllowed GatedAPIFeatures = "SharedArrayBuffersTransferAllowed"
GatedAPIFeaturesPerformanceMeasureMemory GatedAPIFeatures = "PerformanceMeasureMemory"
GatedAPIFeaturesPerformanceProfile GatedAPIFeatures = "PerformanceProfile"
)
func (t GatedAPIFeatures ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t GatedAPIFeatures ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *GatedAPIFeatures ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch GatedAPIFeatures (v ) {
case GatedAPIFeaturesSharedArrayBuffers :
*t = GatedAPIFeaturesSharedArrayBuffers
case GatedAPIFeaturesSharedArrayBuffersTransferAllowed :
*t = GatedAPIFeaturesSharedArrayBuffersTransferAllowed
case GatedAPIFeaturesPerformanceMeasureMemory :
*t = GatedAPIFeaturesPerformanceMeasureMemory
case GatedAPIFeaturesPerformanceProfile :
*t = GatedAPIFeaturesPerformanceProfile
default :
in .AddError (fmt .Errorf ("unknown GatedAPIFeatures value: %v" , v ))
}
}
func (t *GatedAPIFeatures ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type OriginTrialTokenStatus string
func (t OriginTrialTokenStatus ) String () string {
return string (t )
}
const (
OriginTrialTokenStatusSuccess OriginTrialTokenStatus = "Success"
OriginTrialTokenStatusNotSupported OriginTrialTokenStatus = "NotSupported"
OriginTrialTokenStatusInsecure OriginTrialTokenStatus = "Insecure"
OriginTrialTokenStatusExpired OriginTrialTokenStatus = "Expired"
OriginTrialTokenStatusWrongOrigin OriginTrialTokenStatus = "WrongOrigin"
OriginTrialTokenStatusInvalidSignature OriginTrialTokenStatus = "InvalidSignature"
OriginTrialTokenStatusMalformed OriginTrialTokenStatus = "Malformed"
OriginTrialTokenStatusWrongVersion OriginTrialTokenStatus = "WrongVersion"
OriginTrialTokenStatusFeatureDisabled OriginTrialTokenStatus = "FeatureDisabled"
OriginTrialTokenStatusTokenDisabled OriginTrialTokenStatus = "TokenDisabled"
OriginTrialTokenStatusFeatureDisabledForUser OriginTrialTokenStatus = "FeatureDisabledForUser"
OriginTrialTokenStatusUnknownTrial OriginTrialTokenStatus = "UnknownTrial"
)
func (t OriginTrialTokenStatus ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t OriginTrialTokenStatus ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *OriginTrialTokenStatus ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch OriginTrialTokenStatus (v ) {
case OriginTrialTokenStatusSuccess :
*t = OriginTrialTokenStatusSuccess
case OriginTrialTokenStatusNotSupported :
*t = OriginTrialTokenStatusNotSupported
case OriginTrialTokenStatusInsecure :
*t = OriginTrialTokenStatusInsecure
case OriginTrialTokenStatusExpired :
*t = OriginTrialTokenStatusExpired
case OriginTrialTokenStatusWrongOrigin :
*t = OriginTrialTokenStatusWrongOrigin
case OriginTrialTokenStatusInvalidSignature :
*t = OriginTrialTokenStatusInvalidSignature
case OriginTrialTokenStatusMalformed :
*t = OriginTrialTokenStatusMalformed
case OriginTrialTokenStatusWrongVersion :
*t = OriginTrialTokenStatusWrongVersion
case OriginTrialTokenStatusFeatureDisabled :
*t = OriginTrialTokenStatusFeatureDisabled
case OriginTrialTokenStatusTokenDisabled :
*t = OriginTrialTokenStatusTokenDisabled
case OriginTrialTokenStatusFeatureDisabledForUser :
*t = OriginTrialTokenStatusFeatureDisabledForUser
case OriginTrialTokenStatusUnknownTrial :
*t = OriginTrialTokenStatusUnknownTrial
default :
in .AddError (fmt .Errorf ("unknown OriginTrialTokenStatus value: %v" , v ))
}
}
func (t *OriginTrialTokenStatus ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type OriginTrialStatus string
func (t OriginTrialStatus ) String () string {
return string (t )
}
const (
OriginTrialStatusEnabled OriginTrialStatus = "Enabled"
OriginTrialStatusValidTokenNotProvided OriginTrialStatus = "ValidTokenNotProvided"
OriginTrialStatusOSNotSupported OriginTrialStatus = "OSNotSupported"
OriginTrialStatusTrialNotAllowed OriginTrialStatus = "TrialNotAllowed"
)
func (t OriginTrialStatus ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t OriginTrialStatus ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *OriginTrialStatus ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch OriginTrialStatus (v ) {
case OriginTrialStatusEnabled :
*t = OriginTrialStatusEnabled
case OriginTrialStatusValidTokenNotProvided :
*t = OriginTrialStatusValidTokenNotProvided
case OriginTrialStatusOSNotSupported :
*t = OriginTrialStatusOSNotSupported
case OriginTrialStatusTrialNotAllowed :
*t = OriginTrialStatusTrialNotAllowed
default :
in .AddError (fmt .Errorf ("unknown OriginTrialStatus value: %v" , v ))
}
}
func (t *OriginTrialStatus ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type OriginTrialUsageRestriction string
func (t OriginTrialUsageRestriction ) String () string {
return string (t )
}
const (
OriginTrialUsageRestrictionNone OriginTrialUsageRestriction = "None"
OriginTrialUsageRestrictionSubset OriginTrialUsageRestriction = "Subset"
)
func (t OriginTrialUsageRestriction ) MarshalEasyJSON (out *jwriter .Writer ) {
out .String (string (t ))
}
func (t OriginTrialUsageRestriction ) MarshalJSON () ([]byte , error ) {
return easyjson .Marshal (t )
}
func (t *OriginTrialUsageRestriction ) UnmarshalEasyJSON (in *jlexer .Lexer ) {
v := in .String ()
switch OriginTrialUsageRestriction (v ) {
case OriginTrialUsageRestrictionNone :
*t = OriginTrialUsageRestrictionNone
case OriginTrialUsageRestrictionSubset :
*t = OriginTrialUsageRestrictionSubset
default :
in .AddError (fmt .Errorf ("unknown OriginTrialUsageRestriction value: %v" , v ))
}
}
func (t *OriginTrialUsageRestriction ) UnmarshalJSON (buf []byte ) error {
return easyjson .Unmarshal (buf , t )
}
type OriginTrialToken struct {
Origin string `json:"origin"`
MatchSubDomains bool `json:"matchSubDomains"`
TrialName string `json:"trialName"`
ExpiryTime *TimeSinceEpoch `json:"expiryTime"`
IsThirdParty bool `json:"isThirdParty"`
UsageRestriction OriginTrialUsageRestriction `json:"usageRestriction"`
}
type OriginTrialTokenWithStatus struct {
RawTokenText string `json:"rawTokenText"`
ParsedToken *OriginTrialToken `json:"parsedToken,omitempty"`
Status OriginTrialTokenStatus `json:"status"`
}
type OriginTrial struct {
TrialName string `json:"trialName"`
Status OriginTrialStatus `json:"status"`
TokensWithStatus []*OriginTrialTokenWithStatus `json:"tokensWithStatus"`
}
type Frame struct {
ID FrameID `json:"id"`
ParentID FrameID `json:"parentId,omitempty"`
LoaderID LoaderID `json:"loaderId"`
Name string `json:"name,omitempty"`
URL string `json:"url"`
URLFragment string `json:"urlFragment,omitempty"`
DomainAndRegistry string `json:"domainAndRegistry"`
SecurityOrigin string `json:"securityOrigin"`
MimeType string `json:"mimeType"`
UnreachableURL string `json:"unreachableUrl,omitempty"`
AdFrameStatus *AdFrameStatus `json:"adFrameStatus,omitempty"`
SecureContextType SecureContextType `json:"secureContextType"`
CrossOriginIsolatedContextType CrossOriginIsolatedContextType `json:"crossOriginIsolatedContextType"`
GatedAPIFeatures []GatedAPIFeatures `json:"gatedAPIFeatures"`
State FrameState `json:"-"`
Root *Node `json:"-"`
Nodes map [NodeID ]*Node `json:"-"`
sync .RWMutex `json:"-"`
}
type FrameState uint16
const (
FrameDOMContentEventFired FrameState = 1 << (15 - iota )
FrameLoadEventFired
FrameAttached
FrameNavigated
FrameLoading
FrameScheduledNavigation
)
var frameStateNames = map [FrameState ]string {
FrameDOMContentEventFired : "DOMContentEventFired" ,
FrameLoadEventFired : "LoadEventFired" ,
FrameAttached : "Attached" ,
FrameNavigated : "Navigated" ,
FrameLoading : "Loading" ,
FrameScheduledNavigation : "ScheduledNavigation" ,
}
func (fs FrameState ) String () string {
var s []string
for k , v := range frameStateNames {
if fs &k != 0 {
s = append (s , v )
}
}
return "[" + strings .Join (s , " " ) + "]"
}
const EmptyFrameID = FrameID ("" )
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .