Skip to content

Commit

Permalink
feat: include vendor-prefixed additional request data (#2406)
Browse files Browse the repository at this point in the history
- 'goog:postData'
- 'goog:hasPostData'
- 'goog:resourceType'

The testing is planned via Puppeteer.
  • Loading branch information
OrKoN authored Jul 12, 2024
1 parent 6e84815 commit 76bce85
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 61 deletions.
4 changes: 4 additions & 0 deletions src/bidiMapper/modules/network/NetworkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ export class NetworkRequest {
headersSize: computeHeadersSize(headers),
bodySize: this.#bodySize,
timings: this.#timings,
// @ts-expect-error CDP-specific attribute.
'goog:postData': this.#request.info?.request?.postData,
'goog:hasPostData': this.#request.info?.request?.hasPostData,
'goog:resourceType': this.#request.info?.type,
};
}

Expand Down
9 changes: 5 additions & 4 deletions tests/network/test_add_intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import pytest
from anys import ANY_DICT, ANY_LIST, ANY_NUMBER, ANY_STR
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, execute_command,
send_JSON_command, subscribe, wait_for_event)
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, AnyExtending,
execute_command, send_JSON_command, subscribe,
wait_for_event)


@pytest.mark.asyncio
Expand Down Expand Up @@ -306,7 +307,7 @@ async def test_add_intercept_blocks(

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"intercepts": [result["intercept"]],
Expand All @@ -330,4 +331,4 @@ async def test_add_intercept_blocks(
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
18 changes: 9 additions & 9 deletions tests/network/test_continue_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.
import pytest
from anys import ANY_DICT, ANY_LIST, ANY_NUMBER, ANY_STR
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, create_request_via_fetch,
execute_command, goto_url, send_JSON_command,
subscribe, wait_for_event)
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, AnyExtending,
create_request_via_fetch, execute_command, goto_url,
send_JSON_command, subscribe, wait_for_event)

from . import create_blocked_request

Expand Down Expand Up @@ -182,7 +182,7 @@ async def test_continue_request_completes(websocket, context_id, url_example):

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -207,7 +207,7 @@ async def test_continue_request_completes(websocket, context_id, url_example):
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await execute_command(
Expand Down Expand Up @@ -266,7 +266,7 @@ async def test_continue_request_twice(websocket, context_id, url_example):

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -290,7 +290,7 @@ async def test_continue_request_twice(websocket, context_id, url_example):
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await execute_command(
Expand Down Expand Up @@ -353,7 +353,7 @@ async def test_continue_request_remove_intercept_inflight_request(

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -377,7 +377,7 @@ async def test_continue_request_remove_intercept_inflight_request(
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})

result = await execute_command(
websocket, {
Expand Down
4 changes: 2 additions & 2 deletions tests/network/test_continue_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async def test_continue_response_twice(websocket, context_id, url_example):
})

event_response = await wait_for_event(websocket, "network.responseStarted")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.responseStarted",
"params": {
"context": context_id,
Expand All @@ -407,7 +407,7 @@ async def test_continue_response_twice(websocket, context_id, url_example):
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await execute_command(
Expand Down
13 changes: 7 additions & 6 deletions tests/network/test_continue_with_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# limitations under the License.
import pytest
from anys import ANY_DICT, ANY_LIST, ANY_NUMBER, ANY_STR
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, execute_command, goto_url,
send_JSON_command, subscribe, wait_for_event)
from test_helpers import (ANY_TIMESTAMP, ANY_UUID, AnyExtending,
execute_command, goto_url, send_JSON_command,
subscribe, wait_for_event)

from . import create_blocked_request

Expand Down Expand Up @@ -175,7 +176,7 @@ async def test_continue_with_auth_completes(websocket, context_id,
})

event_response = await wait_for_event(websocket, "network.authRequired")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.authRequired",
"params": {
"context": context_id,
Expand All @@ -197,7 +198,7 @@ async def test_continue_with_auth_completes(websocket, context_id,
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await execute_command(
Expand Down Expand Up @@ -256,7 +257,7 @@ async def test_continue_with_auth_twice(websocket, context_id,
})

event_response = await wait_for_event(websocket, "network.authRequired")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.authRequired",
"params": {
"context": context_id,
Expand All @@ -278,7 +279,7 @@ async def test_continue_with_auth_twice(websocket, context_id,
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await execute_command(
Expand Down
24 changes: 12 additions & 12 deletions tests/network/test_fail_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def test_fail_request_twice(websocket, context_id, url_example):

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -138,7 +138,7 @@ async def test_fail_request_twice(websocket, context_id, url_example):
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

result = await execute_command(websocket, {
Expand Down Expand Up @@ -220,7 +220,7 @@ async def test_fail_request_completes(websocket, context_id, url_example):

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -244,7 +244,7 @@ async def test_fail_request_completes(websocket, context_id, url_example):
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

await subscribe(websocket, ["network.fetchError"])
Expand Down Expand Up @@ -331,7 +331,7 @@ async def test_fail_request_completes_new_request_still_blocks(

event_response2 = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response2 == {
assert event_response2 == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -356,7 +356,7 @@ async def test_fail_request_completes_new_request_still_blocks(
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id_2 = event_response2["params"]["request"]["request"]

# The second request should have a different ID.
Expand Down Expand Up @@ -397,7 +397,7 @@ async def test_fail_request_multiple_contexts(websocket, context_id,

event_response1 = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response1 == {
assert event_response1 == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -421,7 +421,7 @@ async def test_fail_request_multiple_contexts(websocket, context_id,
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id_1 = event_response1["params"]["request"]["request"]

# Navigation in second context.
Expand All @@ -437,7 +437,7 @@ async def test_fail_request_multiple_contexts(websocket, context_id,

event_response2 = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response2 == {
assert event_response2 == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": another_context_id,
Expand All @@ -461,7 +461,7 @@ async def test_fail_request_multiple_contexts(websocket, context_id,
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id_2 = event_response2["params"]["request"]["request"]

assert network_id_1 != network_id_2
Expand Down Expand Up @@ -563,7 +563,7 @@ async def test_fail_request_remove_intercept_inflight_request(

event_response = await wait_for_event(websocket,
"network.beforeRequestSent")
assert event_response == {
assert event_response == AnyExtending({
"method": "network.beforeRequestSent",
"params": {
"context": context_id,
Expand All @@ -587,7 +587,7 @@ async def test_fail_request_remove_intercept_inflight_request(
"timestamp": ANY_TIMESTAMP,
},
"type": "event",
}
})
network_id = event_response["params"]["request"]["request"]

result = await execute_command(
Expand Down
Loading

0 comments on commit 76bce85

Please sign in to comment.