diff --git a/cdp/types.go b/cdp/types.go index aa2770f..8b9014a 100644 --- a/cdp/types.go +++ b/cdp/types.go @@ -726,7 +726,7 @@ func (t TimeSinceEpoch) Time() time.Time { // MarshalEasyJSON satisfies easyjson.Marshaler. func (t TimeSinceEpoch) MarshalEasyJSON(out *jwriter.Writer) { - v := float64(time.Time(t).UnixNano() / int64(time.Millisecond)) + 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) @@ -739,7 +739,7 @@ func (t TimeSinceEpoch) MarshalJSON() ([]byte, error) { // UnmarshalEasyJSON satisfies easyjson.Unmarshaler. func (t *TimeSinceEpoch) UnmarshalEasyJSON(in *jlexer.Lexer) { - *t = TimeSinceEpoch(time.Unix(0, int64(in.Float64()*float64(time.Millisecond)))) + *t = TimeSinceEpoch(time.Unix(0, int64(in.Float64()*float64(time.Second)))) } // UnmarshalJSON satisfies json.Unmarshaler. @@ -790,6 +790,40 @@ func (t *MonotonicTime) UnmarshalJSON(buf []byte) error { return easyjson.Unmarshal(buf, t) } +// TimeSinceEpochMilli special timestamp type for Response's responseTime +// field. +// +// See: https://chromedevtools.github.io/devtools-protocol/tot/Network#type-TimeSinceEpochMilli +type TimeSinceEpochMilli time.Time + +// Time returns the TimeSinceEpochMilli as time.Time value. +func (t TimeSinceEpochMilli) Time() time.Time { + return time.Time(t) +} + +// MarshalEasyJSON satisfies easyjson.Marshaler. +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) +} + +// MarshalJSON satisfies json.Marshaler. +func (t TimeSinceEpochMilli) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *TimeSinceEpochMilli) UnmarshalEasyJSON(in *jlexer.Lexer) { + *t = TimeSinceEpochMilli(time.Unix(0, int64(in.Float64()*float64(time.Millisecond)))) +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *TimeSinceEpochMilli) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +} + // FrameID unique frame identifier. // // See: https://chromedevtools.github.io/devtools-protocol/tot/Page#type-FrameId diff --git a/input/types.go b/input/types.go index f90d2ac..8c0c11c 100644 --- a/input/types.go +++ b/input/types.go @@ -146,7 +146,7 @@ func (t TimeSinceEpoch) Time() time.Time { // MarshalEasyJSON satisfies easyjson.Marshaler. func (t TimeSinceEpoch) MarshalEasyJSON(out *jwriter.Writer) { - v := float64(time.Time(t).UnixNano() / int64(time.Millisecond)) + 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) @@ -159,7 +159,7 @@ func (t TimeSinceEpoch) MarshalJSON() ([]byte, error) { // UnmarshalEasyJSON satisfies easyjson.Unmarshaler. func (t *TimeSinceEpoch) UnmarshalEasyJSON(in *jlexer.Lexer) { - *t = TimeSinceEpoch(time.Unix(0, int64(in.Float64()*float64(time.Millisecond)))) + *t = TimeSinceEpoch(time.Unix(0, int64(in.Float64()*float64(time.Second)))) } // UnmarshalJSON satisfies json.Unmarshaler. diff --git a/network/easyjson.go b/network/easyjson.go index ddfa3b9..3362a30 100644 --- a/network/easyjson.go +++ b/network/easyjson.go @@ -2819,7 +2819,7 @@ func easyjsonC5a4559bDecodeGithubComChromedpCdprotoNetwork23(in *jlexer.Lexer, o out.ResponseTime = nil } else { if out.ResponseTime == nil { - out.ResponseTime = new(cdp.TimeSinceEpoch) + out.ResponseTime = new(cdp.TimeSinceEpochMilli) } (*out.ResponseTime).UnmarshalEasyJSON(in) } diff --git a/network/types.go b/network/types.go index 2ccb673..068fa9c 100644 --- a/network/types.go +++ b/network/types.go @@ -1025,7 +1025,7 @@ type Response struct { EncodedDataLength float64 `json:"encodedDataLength"` // Total number of bytes received for this request so far. Timing *ResourceTiming `json:"timing,omitempty"` // Timing information for the given request. ServiceWorkerResponseSource ServiceWorkerResponseSource `json:"serviceWorkerResponseSource,omitempty"` // Response source of response from ServiceWorker. - ResponseTime *cdp.TimeSinceEpoch `json:"responseTime,omitempty"` // The time at which the returned response was generated. + ResponseTime *cdp.TimeSinceEpochMilli `json:"responseTime,omitempty"` // The time at which the returned response was generated. CacheStorageCacheName string `json:"cacheStorageCacheName,omitempty"` // Cache Storage Cache Name. Protocol string `json:"protocol,omitempty"` // Protocol used to fetch this request. AlternateProtocolUsage AlternateProtocolUsage `json:"alternateProtocolUsage,omitempty"` // The reason why Chrome uses a specific transport protocol for HTTP semantics.