Skip to content

Commit b1e5ffa

Browse files
committed
Add Network module
This is designed to support logging network requests. Important use cases include: * Determing if a specific network request occured * Monitoring request performance * Generating a HAR file for offline analysis of requests This does not currently attempt to support network request interception (i.e. mutable access to requests), but the intent is that the same lifecycle events could be used in a blocking way. It also currently only supports HTTP-type requests and not e.g. WebSockets. Some support for integration with service workers is also missing. The typical order of events is network.beforeRequestSent - before request is sent, would later be the right point to change the request headers or body or prevent the request entirely. network.responseStarted - after response headers are received, but before body. Would later be a point to override the response headers or body. network.responseCompleted - after the request is fully complete. network.fetchError - After any error that will prevent the request from completing. Compared to CDP this is missing an event for data being received. Compared to WebExtensions, this is missing an event after the headers are sent but before the data is sent.
1 parent 6f3901e commit b1e5ffa

File tree

1 file changed

+272
-3
lines changed

1 file changed

+272
-3
lines changed

index.bs

+272-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ Command = {
253253

254254
CommandData = (
255255
SessionCommand //
256-
BrowsingContextCommand
256+
BrowsingContextCommand //
257+
NetworkCommand //
258+
ScriptCommand
257259
)
258260

259261
EmptyParams = { *text }
@@ -286,6 +288,7 @@ ResultData = (
286288
EmptyResult //
287289
SessionResult //
288290
BrowsingContextResult //
291+
NetworkResult //
289292
ScriptResult
290293
)
291294

@@ -298,8 +301,9 @@ Event = {
298301

299302
EventData = (
300303
BrowsingContextEvent //
301-
ScriptEvent //
302-
LogEvent
304+
LogEvent //
305+
NetworkEvent //
306+
ScriptEvent
303307
)
304308
</pre>
305309

@@ -3631,6 +3635,271 @@ opened</dfn> steps given |window|, |type| and |message|.
36313635

36323636
</div>
36333637

3638+
## The network Module ## {#module-network}
3639+
3640+
The <dfn export for=modules>network</dfn> module contains commands and events
3641+
relating to network requests.
3642+
3643+
### Definition ### {#module-network-definition}
3644+
3645+
<pre class="cddl remote-cddl">
3646+
3647+
NetworkCommand = (
3648+
)
3649+
3650+
</pre>
3651+
3652+
[=local end definition=]
3653+
3654+
<pre class="cddl local-cddl">
3655+
3656+
NetworkResult = (
3657+
)
3658+
3659+
NetworkEvent = (
3660+
NetworkBeforeSendRequest //
3661+
NetworkResponseStarted //
3662+
NetworkResponseCompleted //
3663+
NetworkError
3664+
)
3665+
3666+
</pre>
3667+
3668+
### Types ### {#module-network-types}
3669+
3670+
#### The network.Cookie type #### {#type-network-Cookie}
3671+
3672+
[=Remote end definition=] and [=local end definition=]
3673+
3674+
<pre class="cddl local-cddl">
3675+
NetworkCookie = {
3676+
name: text,
3677+
? value: text,
3678+
? binaryValue: [ uint ]
3679+
domain: text,
3680+
path: text,
3681+
expires: uint,
3682+
size: unit,
3683+
httpOnly: boolean,
3684+
secure: boolean,
3685+
session: boolean,
3686+
sameSite: "strict" / "lax" / "none",
3687+
};
3688+
</pre>
3689+
3690+
The <code>NetworkCookie</code> type represents a cookie.
3691+
3692+
If the cookie value can be represented as a UTF-8 encoded string, the
3693+
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
3694+
field will be present and consist of an array of integers representing the bytes
3695+
of the cookie value.
3696+
3697+
#### The network.FetchTimingInfo type #### {#type-network-FetchTimingInfo}
3698+
3699+
[=Remote end definition=] and [=local end definition=]
3700+
3701+
<pre class="cddl local-cddl">
3702+
NetworkFetchTimingInfo = {
3703+
requestTime: uint,
3704+
redirectStart: uint,
3705+
redirectEnd: uint,
3706+
fetchStart: uint,
3707+
dnsStart: uint,
3708+
dnsEnd: uint,
3709+
connectStart: uint,
3710+
connectEnd: uint,
3711+
tlsStart: uint,
3712+
tlsEnd: uint,
3713+
requestStart: uint,
3714+
responseStart: uint,
3715+
responseHeadersEnd: uint,
3716+
responseEnd: uint,
3717+
};
3718+
</pre>
3719+
3720+
The <code>NetworkFetchTimingInfo</code> type represents the time of each part of
3721+
the request, relative to <code>requestTime</code>.
3722+
3723+
TODO: Add service worker fields
3724+
3725+
#### The network.Header type #### {#type-network-Header}
3726+
3727+
[=Remote end definition=] and [=local end definition=]
3728+
3729+
<pre class="cddl local-cddl">
3730+
NetworkHeader = {
3731+
name: text,
3732+
? value: text,
3733+
? binaryValue: [ uint ]
3734+
};
3735+
</pre>
3736+
3737+
The <code>NetworkHeader</code> type represents a single request header.
3738+
3739+
If the header value can be represented as a UTF-8 encoded string, the
3740+
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
3741+
field will be present and consist of an array of integers representing the bytes
3742+
of the header.
3743+
3744+
#### The network.Initiator type #### {#type-network-Initiator}
3745+
3746+
[=Remote end definition=] and [=local end definition=]
3747+
3748+
<pre class="cddl local-cddl">
3749+
NetworkInitiator = {
3750+
type: "parser" / "script" / "preflight" / "other",
3751+
?columnNumber: uint,
3752+
?lineNumber: uint,
3753+
?stackTrace: StackTrace,
3754+
?request: NetworkRequest
3755+
};
3756+
</pre>
3757+
3758+
The <code>NetworkInitiatior</code> type represents the source of a network request.
3759+
3760+
TODO: Align more closely with Fetch here?
3761+
3762+
#### The network.Request type #### {#type-network-RequestId}
3763+
3764+
[=Remote end definition=] and [=local end definition=]
3765+
3766+
<pre class="cddl local-cddl remote-cddl">
3767+
NetworkRequest = text;
3768+
</pre>
3769+
3770+
Each network request has an associated <dfn export>request id</dfn>, which is a string
3771+
uniquely identifying that request.
3772+
3773+
#### The network.RequestData type #### {#type-network-RequestData}
3774+
3775+
[=Remote end definition=] and [=local end definition=]
3776+
3777+
<pre class="cddl local-cddl">
3778+
NetworkRequestData = {
3779+
url: text,
3780+
method: text,
3781+
headers: [ *NetworkHeader ],
3782+
cookies: [ *NetworkCookie ],
3783+
?body: text,
3784+
bodySize: uint,
3785+
headersSize: uint
3786+
};
3787+
</pre>
3788+
3789+
The <code>RequestData</code> type represents an ongoing network request.
3790+
3791+
TODO: Body is actually bytes, not clear how to handle it as text
3792+
3793+
#### The network.ResponseData type #### {#type-network-ResponseData}
3794+
3795+
[=Remote end definition=] and [=local end definition=]
3796+
3797+
<pre class="cddl local-cddl">
3798+
NetworkResponseData = {
3799+
url: text,
3800+
protocol: text,
3801+
status: unit,
3802+
statusText: text,
3803+
headers: [ *NetworkHeader ],
3804+
cookies: [ *NetworkCookie ],
3805+
mimeType: text,
3806+
bytesReceived: uint,
3807+
timings: NetworkFetchTimingInfo,
3808+
};
3809+
</pre>
3810+
3811+
### Events ### {#module-network-events}
3812+
3813+
#### The network.beforeRequestSent Event #### {#event-network-beforeSendRequest}
3814+
<dl>
3815+
<dt>Event Type</dt>
3816+
<dd>
3817+
<pre class="cddl local-cddl">
3818+
NetworkBeforeRequestSentEvent = {
3819+
method: "network.beforeRequestSent",
3820+
params: NetworkBeforeRequestSentParams
3821+
}
3822+
3823+
NetworkBeforeRequestSentParams = {
3824+
request: NetworkRequest,
3825+
navigation: Navigation / null,
3826+
context: BrowsingContext / null,
3827+
requestData: NetworkRequestData,
3828+
initiator: NetworkInitiator
3829+
timestamp: number,
3830+
}
3831+
</pre>
3832+
</dd>
3833+
</dl>
3834+
3835+
#### The network.fetchError Event #### {#event-network-fetchError}
3836+
3837+
<dl>
3838+
<dt>Event Type</dt>
3839+
<dd>
3840+
<pre class="cddl local-cddl">
3841+
NetworkFetchErrorEvent = {
3842+
method: "network.fetchError",
3843+
params: NetworkFetchErrorParams
3844+
}
3845+
3846+
NetworkFetchErrorParams = {
3847+
request: NetworkRequest,
3848+
errorText: text,
3849+
timestamp: number,
3850+
}
3851+
</pre>
3852+
</dd>
3853+
</dl>
3854+
3855+
#### The network.responseCompleted Event #### {#event-network-responseCompleted}
3856+
3857+
<dl>
3858+
<dt>Event Type</dt>
3859+
<dd>
3860+
<pre class="cddl local-cddl">
3861+
NetworkResponseCompletedEvent = {
3862+
method: "network.responseCompleted",
3863+
params: NetworkResponseCompleteParams
3864+
}
3865+
3866+
NetworkResponseCompletedParams = {
3867+
request: NetworkRequest,
3868+
navigation: Navigation / null,
3869+
context: BrowsingContext / null,
3870+
responseData: NetworkResponseData,
3871+
timestamp: number,
3872+
}
3873+
</pre>
3874+
</dd>
3875+
</dl>
3876+
3877+
After the full response body is received.
3878+
3879+
#### The network.responseStarted Event #### {#event-network-responseStarted}
3880+
3881+
<dl>
3882+
<dt>Event Type</dt>
3883+
<dd>
3884+
<pre class="cddl local-cddl">
3885+
NetworkResponseStartedEvent = {
3886+
method: "network.responseStartedEvent",
3887+
params: NetworkResponseStartedParams
3888+
}
3889+
3890+
NetworkResponseStartedParams = {
3891+
request: NetworkRequest,
3892+
navigaton: Navigation / null,
3893+
context: BrowsingContext / null,
3894+
responseData: NetworkResponseData,
3895+
timestamp: number,
3896+
}
3897+
</pre>
3898+
</dd>
3899+
</dl>
3900+
3901+
After the response headers are received but before the body.
3902+
36343903
## The script Module ## {#module-script}
36353904

36363905
The <dfn export for=modules>script</dfn> module contains commands and events

0 commit comments

Comments
 (0)