Skip to content

Commit 22a36b7

Browse files
committed
Fix CDP errors in Network domain - two booleans not marked as optional
1 parent fe9ac76 commit 22a36b7

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

cdp/network.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,7 +3090,7 @@ class RequestWillBeSent:
30903090
#: In the case that redirectResponse is populated, this flag indicates whether
30913091
#: requestWillBeSentExtraInfo and responseReceivedExtraInfo events will be or were emitted
30923092
#: for the request which was just redirected.
3093-
redirect_has_extra_info: bool
3093+
redirect_has_extra_info: typing.Optional[bool]
30943094
#: Redirect response data.
30953095
redirect_response: typing.Optional[Response]
30963096
#: Type of this resource.
@@ -3110,7 +3110,7 @@ def from_json(cls, json: T_JSON_DICT) -> RequestWillBeSent:
31103110
timestamp=MonotonicTime.from_json(json['timestamp']),
31113111
wall_time=TimeSinceEpoch.from_json(json['wallTime']),
31123112
initiator=Initiator.from_json(json['initiator']),
3113-
redirect_has_extra_info=bool(json['redirectHasExtraInfo']),
3113+
redirect_has_extra_info=bool(json['redirectHasExtraInfo']) if 'redirectHasExtraInfo' in json else None,
31143114
redirect_response=Response.from_json(json['redirectResponse']) if 'redirectResponse' in json else None,
31153115
type_=ResourceType.from_json(json['type']) if 'type' in json else None,
31163116
frame_id=page.FrameId.from_json(json['frameId']) if 'frameId' in json else None,
@@ -3181,7 +3181,7 @@ class ResponseReceived:
31813181
response: Response
31823182
#: Indicates whether requestWillBeSentExtraInfo and responseReceivedExtraInfo events will be
31833183
#: or were emitted for this request.
3184-
has_extra_info: bool
3184+
has_extra_info: typing.Optional[bool]
31853185
#: Frame identifier.
31863186
frame_id: typing.Optional[page.FrameId]
31873187

@@ -3193,7 +3193,7 @@ def from_json(cls, json: T_JSON_DICT) -> ResponseReceived:
31933193
timestamp=MonotonicTime.from_json(json['timestamp']),
31943194
type_=ResourceType.from_json(json['type']),
31953195
response=Response.from_json(json['response']),
3196-
has_extra_info=bool(json['hasExtraInfo']),
3196+
has_extra_info=bool(json['hasExtraInfo']) if 'hasExtraInfo' in json else None,
31973197
frame_id=page.FrameId.from_json(json['frameId']) if 'frameId' in json else None
31983198
)
31993199

generator/generate.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,38 @@ def generate_docs(docs_path, domains):
952952
f.write(domain.generate_sphinx())
953953

954954

955+
def patchCDP(domains):
956+
'''Patch up CDP errors. It's easier to patch that here than it is to modify the generator code.'''
957+
958+
# 1. DOM includes an erroneous $ref that refers to itself.
959+
# 2. Page includes an event with an extraneous backtick in the description.
960+
# 3. Network.requestWillBeSent.redirectHasExtraInfo is not marked as optional but it is not present in all events
961+
# 4. Network.responseReceived.hasExtraInfo is not marked as optional but it is not present in all events
962+
for domain in domains:
963+
if domain.domain == 'DOM':
964+
for cmd in domain.commands:
965+
if cmd.name == 'resolveNode':
966+
# Patch 1
967+
cmd.parameters[1].ref = 'BackendNodeId'
968+
elif domain.domain == 'Page':
969+
for event in domain.events:
970+
if event.name == 'screencastVisibilityChanged':
971+
# Patch 2
972+
event.description = event.description.replace('`', '')
973+
elif domain.domain == 'Network':
974+
for event in domain.events:
975+
if event.name == 'requestWillBeSent':
976+
for param in event.parameters:
977+
if param.name == 'redirectHasExtraInfo':
978+
# Patch 3
979+
param.optional = True
980+
if event.name == 'responseReceived':
981+
for param in event.parameters:
982+
if param.name == 'hasExtraInfo':
983+
# Patch 4
984+
param.optional = True
985+
986+
955987
def main():
956988
''' Main entry point. '''
957989
here = Path(__file__).parent.resolve()
@@ -974,21 +1006,7 @@ def main():
9741006
domains.extend(parse(json_path, output_path))
9751007
domains.sort(key=operator.attrgetter('domain'))
9761008

977-
# Patch up CDP errors. It's easier to patch that here than it is to modify
978-
# the generator code.
979-
# 1. DOM includes an erroneous $ref that refers to itself.
980-
# 2. Page includes an event with an extraneous backtick in the description.
981-
for domain in domains:
982-
if domain.domain == 'DOM':
983-
for cmd in domain.commands:
984-
if cmd.name == 'resolveNode':
985-
# Patch 1
986-
cmd.parameters[1].ref = 'BackendNodeId'
987-
elif domain.domain == 'Page':
988-
for event in domain.events:
989-
if event.name == 'screencastVisibilityChanged':
990-
# Patch 2
991-
event.description = event.description.replace('`', '')
1009+
patchCDP(domains)
9921010

9931011
for domain in domains:
9941012
logger.info('Generating module: %s → %s.py', domain.domain,

0 commit comments

Comments
 (0)