change(tracker/player): create new network msg for cached req
This commit is contained in:
parent
1afd130c90
commit
2f1b233070
7 changed files with 132 additions and 20 deletions
|
|
@ -22,7 +22,7 @@ const (
|
||||||
MsgSetInputValue = 18
|
MsgSetInputValue = 18
|
||||||
MsgSetInputChecked = 19
|
MsgSetInputChecked = 19
|
||||||
MsgMouseMove = 20
|
MsgMouseMove = 20
|
||||||
MsgNetworkRequest = 21
|
MsgLegacyNetworkRequest = 21
|
||||||
MsgConsoleLog = 22
|
MsgConsoleLog = 22
|
||||||
MsgPageLoadTiming = 23
|
MsgPageLoadTiming = 23
|
||||||
MsgPageRenderTiming = 24
|
MsgPageRenderTiming = 24
|
||||||
|
|
@ -83,6 +83,7 @@ const (
|
||||||
MsgIssueEvent = 125
|
MsgIssueEvent = 125
|
||||||
MsgSessionEnd = 126
|
MsgSessionEnd = 126
|
||||||
MsgSessionSearch = 127
|
MsgSessionSearch = 127
|
||||||
|
MsgNetworkRequest = 128
|
||||||
MsgIOSBatchMeta = 107
|
MsgIOSBatchMeta = 107
|
||||||
MsgIOSSessionStart = 90
|
MsgIOSSessionStart = 90
|
||||||
MsgIOSSessionEnd = 91
|
MsgIOSSessionEnd = 91
|
||||||
|
|
@ -601,7 +602,7 @@ func (msg *MouseMove) TypeID() int {
|
||||||
return 20
|
return 20
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetworkRequest struct {
|
type LegacyNetworkRequest struct {
|
||||||
message
|
message
|
||||||
Type string
|
Type string
|
||||||
Method string
|
Method string
|
||||||
|
|
@ -613,7 +614,7 @@ type NetworkRequest struct {
|
||||||
Duration uint64
|
Duration uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NetworkRequest) Encode() []byte {
|
func (msg *LegacyNetworkRequest) Encode() []byte {
|
||||||
buf := make([]byte, 81+len(msg.Type)+len(msg.Method)+len(msg.URL)+len(msg.Request)+len(msg.Response))
|
buf := make([]byte, 81+len(msg.Type)+len(msg.Method)+len(msg.URL)+len(msg.Request)+len(msg.Response))
|
||||||
buf[0] = 21
|
buf[0] = 21
|
||||||
p := 1
|
p := 1
|
||||||
|
|
@ -628,11 +629,11 @@ func (msg *NetworkRequest) Encode() []byte {
|
||||||
return buf[:p]
|
return buf[:p]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NetworkRequest) Decode() Message {
|
func (msg *LegacyNetworkRequest) Decode() Message {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NetworkRequest) TypeID() int {
|
func (msg *LegacyNetworkRequest) TypeID() int {
|
||||||
return 21
|
return 21
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2202,6 +2203,43 @@ func (msg *SessionSearch) TypeID() int {
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NetworkRequest struct {
|
||||||
|
message
|
||||||
|
Type string
|
||||||
|
Method string
|
||||||
|
URL string
|
||||||
|
Request string
|
||||||
|
Response string
|
||||||
|
Status uint64
|
||||||
|
Timestamp uint64
|
||||||
|
Duration uint64
|
||||||
|
Cached bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *NetworkRequest) Encode() []byte {
|
||||||
|
buf := make([]byte, 91+len(msg.Type)+len(msg.Method)+len(msg.URL)+len(msg.Request)+len(msg.Response))
|
||||||
|
buf[0] = 128
|
||||||
|
p := 1
|
||||||
|
p = WriteString(msg.Type, buf, p)
|
||||||
|
p = WriteString(msg.Method, buf, p)
|
||||||
|
p = WriteString(msg.URL, buf, p)
|
||||||
|
p = WriteString(msg.Request, buf, p)
|
||||||
|
p = WriteString(msg.Response, buf, p)
|
||||||
|
p = WriteUint(msg.Status, buf, p)
|
||||||
|
p = WriteUint(msg.Timestamp, buf, p)
|
||||||
|
p = WriteUint(msg.Duration, buf, p)
|
||||||
|
p = WriteBoolean(msg.Cached, buf, p)
|
||||||
|
return buf[:p]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *NetworkRequest) Decode() Message {
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *NetworkRequest) TypeID() int {
|
||||||
|
return 128
|
||||||
|
}
|
||||||
|
|
||||||
type IOSBatchMeta struct {
|
type IOSBatchMeta struct {
|
||||||
message
|
message
|
||||||
Timestamp uint64
|
Timestamp uint64
|
||||||
|
|
|
||||||
|
|
@ -300,9 +300,9 @@ func DecodeMouseMove(reader BytesReader) (Message, error) {
|
||||||
return msg, err
|
return msg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeNetworkRequest(reader BytesReader) (Message, error) {
|
func DecodeLegacyNetworkRequest(reader BytesReader) (Message, error) {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
msg := &NetworkRequest{}
|
msg := &LegacyNetworkRequest{}
|
||||||
if msg.Type, err = reader.ReadString(); err != nil {
|
if msg.Type, err = reader.ReadString(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1329,6 +1329,39 @@ func DecodeSessionSearch(reader BytesReader) (Message, error) {
|
||||||
return msg, err
|
return msg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeNetworkRequest(reader BytesReader) (Message, error) {
|
||||||
|
var err error = nil
|
||||||
|
msg := &NetworkRequest{}
|
||||||
|
if msg.Type, err = reader.ReadString(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Method, err = reader.ReadString(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.URL, err = reader.ReadString(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Request, err = reader.ReadString(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Response, err = reader.ReadString(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Status, err = reader.ReadUint(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Timestamp, err = reader.ReadUint(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Duration, err = reader.ReadUint(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if msg.Cached, err = reader.ReadBoolean(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return msg, err
|
||||||
|
}
|
||||||
|
|
||||||
func DecodeIOSBatchMeta(reader BytesReader) (Message, error) {
|
func DecodeIOSBatchMeta(reader BytesReader) (Message, error) {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
msg := &IOSBatchMeta{}
|
msg := &IOSBatchMeta{}
|
||||||
|
|
@ -1774,7 +1807,7 @@ func ReadMessage(t uint64, reader BytesReader) (Message, error) {
|
||||||
case 20:
|
case 20:
|
||||||
return DecodeMouseMove(reader)
|
return DecodeMouseMove(reader)
|
||||||
case 21:
|
case 21:
|
||||||
return DecodeNetworkRequest(reader)
|
return DecodeLegacyNetworkRequest(reader)
|
||||||
case 22:
|
case 22:
|
||||||
return DecodeConsoleLog(reader)
|
return DecodeConsoleLog(reader)
|
||||||
case 23:
|
case 23:
|
||||||
|
|
@ -1895,6 +1928,8 @@ func ReadMessage(t uint64, reader BytesReader) (Message, error) {
|
||||||
return DecodeSessionEnd(reader)
|
return DecodeSessionEnd(reader)
|
||||||
case 127:
|
case 127:
|
||||||
return DecodeSessionSearch(reader)
|
return DecodeSessionSearch(reader)
|
||||||
|
case 128:
|
||||||
|
return DecodeNetworkRequest(reader)
|
||||||
case 107:
|
case 107:
|
||||||
return DecodeIOSBatchMeta(reader)
|
return DecodeIOSBatchMeta(reader)
|
||||||
case 90:
|
case 90:
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ class MouseMove(Message):
|
||||||
self.y = y
|
self.y = y
|
||||||
|
|
||||||
|
|
||||||
class NetworkRequest(Message):
|
class LegacyNetworkRequest(Message):
|
||||||
__id__ = 21
|
__id__ = 21
|
||||||
|
|
||||||
def __init__(self, type, method, url, request, response, status, timestamp, duration):
|
def __init__(self, type, method, url, request, response, status, timestamp, duration):
|
||||||
|
|
@ -772,6 +772,21 @@ class SessionSearch(Message):
|
||||||
self.partition = partition
|
self.partition = partition
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkRequest(Message):
|
||||||
|
__id__ = 128
|
||||||
|
|
||||||
|
def __init__(self, type, method, url, request, response, status, timestamp, duration, cached):
|
||||||
|
self.type = type
|
||||||
|
self.method = method
|
||||||
|
self.url = url
|
||||||
|
self.request = request
|
||||||
|
self.response = response
|
||||||
|
self.status = status
|
||||||
|
self.timestamp = timestamp
|
||||||
|
self.duration = duration
|
||||||
|
self.cached = cached
|
||||||
|
|
||||||
|
|
||||||
class IOSBatchMeta(Message):
|
class IOSBatchMeta(Message):
|
||||||
__id__ = 107
|
__id__ = 107
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ class MessageCodec(Codec):
|
||||||
)
|
)
|
||||||
|
|
||||||
if message_id == 21:
|
if message_id == 21:
|
||||||
return NetworkRequest(
|
return LegacyNetworkRequest(
|
||||||
type=self.read_string(reader),
|
type=self.read_string(reader),
|
||||||
method=self.read_string(reader),
|
method=self.read_string(reader),
|
||||||
url=self.read_string(reader),
|
url=self.read_string(reader),
|
||||||
|
|
@ -680,6 +680,19 @@ class MessageCodec(Codec):
|
||||||
partition=self.read_uint(reader)
|
partition=self.read_uint(reader)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if message_id == 128:
|
||||||
|
return NetworkRequest(
|
||||||
|
type=self.read_string(reader),
|
||||||
|
method=self.read_string(reader),
|
||||||
|
url=self.read_string(reader),
|
||||||
|
request=self.read_string(reader),
|
||||||
|
response=self.read_string(reader),
|
||||||
|
status=self.read_uint(reader),
|
||||||
|
timestamp=self.read_uint(reader),
|
||||||
|
duration=self.read_uint(reader),
|
||||||
|
cached=self.read_boolean(reader)
|
||||||
|
)
|
||||||
|
|
||||||
if message_id == 107:
|
if message_id == 107:
|
||||||
return IOSBatchMeta(
|
return IOSBatchMeta(
|
||||||
timestamp=self.read_uint(reader),
|
timestamp=self.read_uint(reader),
|
||||||
|
|
|
||||||
|
|
@ -128,10 +128,10 @@ export function renderDuration(r: any) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderStatus({ status }: { status: string }) {
|
function renderStatus({ status, cached }: { status: string, cached: boolean }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{parseInt(status, 10) === 200 ? (
|
{cached ? (
|
||||||
<Tooltip title={"Served from cache"}>
|
<Tooltip title={"Served from cache"}>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<span className="mr-1">{status}</span>
|
<span className="mr-1">{status}</span>
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ message 20, 'MouseMove' do
|
||||||
uint 'X'
|
uint 'X'
|
||||||
uint 'Y'
|
uint 'Y'
|
||||||
end
|
end
|
||||||
message 21, 'NetworkRequest', :replayer => :devtools do
|
message 21, 'LegacyNetworkRequest', :replayer => :devtools do
|
||||||
string 'Type' # fetch/xhr/anythingElse(axios,gql,fonts,image?)
|
string 'Type' # fetch/xhr/anythingElse(axios,gql,fonts,image?)
|
||||||
string 'Method'
|
string 'Method'
|
||||||
string 'URL'
|
string 'URL'
|
||||||
|
|
@ -490,4 +490,14 @@ message 127, 'SessionSearch', :tracker => false, :replayer => false do
|
||||||
uint 'Partition'
|
uint 'Partition'
|
||||||
end
|
end
|
||||||
|
|
||||||
# since tracker 4.1.10
|
message 128, 'NetworkRequest', :replayer => :devtools do
|
||||||
|
string 'Type' # fetch/xhr/anythingElse(axios,gql,fonts,image?)
|
||||||
|
string 'Method'
|
||||||
|
string 'URL'
|
||||||
|
string 'Request'
|
||||||
|
string 'Response'
|
||||||
|
uint 'Status'
|
||||||
|
uint 'Timestamp'
|
||||||
|
uint 'Duration'
|
||||||
|
boolean 'Cached'
|
||||||
|
end
|
||||||
|
|
@ -39,10 +39,9 @@ function checkCacheByPerformanceTimings(requestUrl: string) {
|
||||||
if (performance) {
|
if (performance) {
|
||||||
const timings = performance.getEntriesByName(requestUrl)[0]
|
const timings = performance.getEntriesByName(requestUrl)[0]
|
||||||
// @ts-ignore - weird ts typings, please refer to https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
// @ts-ignore - weird ts typings, please refer to https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming
|
||||||
if (timings.transferSize === 0 || timings.responseStart - timings.requestStart < 10) {
|
return timings.transferSize === 0 || timings.responseStart - timings.requestStart < 10
|
||||||
return true
|
}
|
||||||
}
|
return false
|
||||||
} else return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestData {
|
interface RequestData {
|
||||||
|
|
@ -229,9 +228,10 @@ export default function (app: App, opts: Partial<Options> = {}) {
|
||||||
String(reqResInfo.url),
|
String(reqResInfo.url),
|
||||||
stringify(reqResInfo.request),
|
stringify(reqResInfo.request),
|
||||||
stringify(reqResInfo.response),
|
stringify(reqResInfo.response),
|
||||||
isCached ? 304 : r.status,
|
r.status,
|
||||||
startTime + getTimeOrigin(),
|
startTime + getTimeOrigin(),
|
||||||
duration,
|
duration,
|
||||||
|
isCached,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -299,9 +299,10 @@ export default function (app: App, opts: Partial<Options> = {}) {
|
||||||
String(reqResInfo.url),
|
String(reqResInfo.url),
|
||||||
stringify(reqResInfo.request),
|
stringify(reqResInfo.request),
|
||||||
stringify(reqResInfo.response),
|
stringify(reqResInfo.response),
|
||||||
isCached ? 304 : xhr.status,
|
xhr.status,
|
||||||
startTime + getTimeOrigin(),
|
startTime + getTimeOrigin(),
|
||||||
duration,
|
duration,
|
||||||
|
isCached,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue