mirror of
https://github.com/lexmount/moli.git
synced 2026-11-22 08:02:23 +00:00
fix(cdp): keep WebSocket handshakes outside Fetch interception
Exclude WebSockets from wildcard and authentication interception classes and reject explicit WebSocket Fetch filters. Publish their handshake and failure through dedicated Network.webSocket events without ordinary HTTP requests. Keep URL blocking and Worker WebSocket diagnostics covered.
This commit is contained in:
@@ -3206,6 +3206,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
owner.configure_fetch(Some("SID-active".to_owned()), true, patterns.clone()),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert!(owner.register_pending_subresource_fetch_request(
|
||||
"FETCH-active".to_owned(),
|
||||
@@ -3242,6 +3243,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
owner.configure_fetch(Some("SID-background".to_owned()), true, patterns),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert!(owner.register_pending_subresource_fetch_request(
|
||||
"FETCH-background".to_owned(),
|
||||
@@ -3712,6 +3714,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
inputs.fetch_subresource_interception,
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3813,6 +3816,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
inputs.fetch_subresource_interception,
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,10 @@ pub struct FetchInterceptionPattern {
|
||||
|
||||
impl FetchInterceptionPattern {
|
||||
pub fn matches_request(&self, resource_type: DevToolsNetworkResourceType, url: &Url) -> bool {
|
||||
self.resource_type_filter
|
||||
.is_none_or(|filter| filter.matches_resource_type(resource_type))
|
||||
resource_type != DevToolsNetworkResourceType::WebSocket
|
||||
&& self
|
||||
.resource_type_filter
|
||||
.is_none_or(|filter| filter.matches_resource_type(resource_type))
|
||||
&& url_pattern_matches(&self.url_pattern, url.as_str())
|
||||
}
|
||||
}
|
||||
@@ -138,7 +140,7 @@ impl FetchResourceTypeFilter {
|
||||
}
|
||||
Self::Ping => SubresourceInterceptionClasses::PING,
|
||||
Self::CspViolationReport => SubresourceInterceptionClasses::CSP_VIOLATION_REPORT,
|
||||
Self::WebSocket => SubresourceInterceptionClasses::WEBSOCKET,
|
||||
Self::WebSocket => SubresourceInterceptionClasses::NONE,
|
||||
Self::Other => SubresourceInterceptionClasses::OTHER,
|
||||
}
|
||||
}
|
||||
@@ -152,19 +154,20 @@ pub fn fetch_subresource_interception_config_for_patterns(
|
||||
return SubresourceInterceptionClasses::NONE;
|
||||
}
|
||||
if patterns.is_empty() {
|
||||
// Fetch.enable without patterns can pause any resource class, so the
|
||||
// renderer must route everything through the protocol and let it
|
||||
// match per request.
|
||||
return SubresourceInterceptionClasses::ALL;
|
||||
// WebSocket handshakes use Network.webSocket* events and are not
|
||||
// intercepted by Fetch, including an unfiltered Fetch.enable.
|
||||
return SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET);
|
||||
}
|
||||
|
||||
// Type-less patterns route every class; typed patterns contribute only
|
||||
// Type-less patterns route HTTP classes; typed patterns contribute only
|
||||
// their supported classes. URL and stage matching stay in the protocol.
|
||||
patterns
|
||||
.iter()
|
||||
.map(|pattern| {
|
||||
pattern.resource_type_filter.map_or(
|
||||
SubresourceInterceptionClasses::ALL,
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET),
|
||||
FetchResourceTypeFilter::interception_classes,
|
||||
)
|
||||
})
|
||||
@@ -1877,7 +1880,6 @@ mod tests {
|
||||
FetchResourceTypeFilter::Xhr,
|
||||
FetchResourceTypeFilter::Ping,
|
||||
FetchResourceTypeFilter::CspViolationReport,
|
||||
FetchResourceTypeFilter::WebSocket,
|
||||
FetchResourceTypeFilter::Other,
|
||||
] {
|
||||
let patterns = [FetchInterceptionPattern {
|
||||
@@ -2042,7 +2044,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_less_and_missing_patterns_intercept_every_class() {
|
||||
fn type_less_and_missing_patterns_intercept_http_classes() {
|
||||
let type_less = vec![FetchInterceptionPattern {
|
||||
url_pattern: "*://example.test/*".to_owned(),
|
||||
resource_type_filter: None,
|
||||
@@ -2051,6 +2053,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
fetch_subresource_interception_config_for_patterns(true, &type_less),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
// A typed pattern next to a type-less one still routes everything.
|
||||
let mixed = vec![
|
||||
@@ -2064,10 +2067,12 @@ mod tests {
|
||||
assert_eq!(
|
||||
fetch_subresource_interception_config_for_patterns(true, &mixed),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert_eq!(
|
||||
fetch_subresource_interception_config_for_patterns(true, &[]),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1134,9 +1134,11 @@ impl TargetFetchConfig {
|
||||
{
|
||||
// Auth challenges are matched by URL alone, regardless of the
|
||||
// resource classes named by Fetch.enable patterns. The renderer
|
||||
// must route every class through the protocol so no class scope
|
||||
// can silently disable Fetch.authRequired pauses.
|
||||
return moli_core::page::SubresourceInterceptionClasses::ALL;
|
||||
// must route HTTP classes through the protocol so no class scope
|
||||
// can silently disable Fetch.authRequired pauses. WebSocket
|
||||
// handshakes are outside Fetch interception.
|
||||
return moli_core::page::SubresourceInterceptionClasses::ALL
|
||||
.difference(moli_core::page::SubresourceInterceptionClasses::WEBSOCKET);
|
||||
}
|
||||
fetch_subresource_interception_config_for_patterns(self.enabled, &self.patterns)
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ fn target_fetch_owner_projects_config_without_exposing_slots() {
|
||||
let snapshot = owner.subresource_interception_snapshot();
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL,
|
||||
"handleAuthRequests routes every class through the protocol"
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET),
|
||||
"handleAuthRequests routes HTTP classes through the protocol"
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.event_session_id(None),
|
||||
@@ -186,7 +186,7 @@ fn target_fetch_owner_projects_config_without_exposing_slots() {
|
||||
DevToolsNetworkResourceType::WebSocket,
|
||||
&Url::parse("wss://example.test/ws").unwrap(),
|
||||
),
|
||||
Some(FetchRequestStage::Request)
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
owner.matching_document_request_stage(&Url::parse("https://example.test/api").unwrap()),
|
||||
@@ -209,7 +209,7 @@ fn target_fetch_owner_projects_config_without_exposing_slots() {
|
||||
);
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL,
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET),
|
||||
"aggregate subresource config keeps handleAuthRequests broad admission"
|
||||
);
|
||||
let root_config = owner.config_snapshot_for_session(None);
|
||||
@@ -345,7 +345,7 @@ fn target_fetch_owner_keeps_fetch_enable_configs_per_session() {
|
||||
assert!(aggregate.handle_auth_requests());
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL,
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET),
|
||||
"aggregate handleAuthRequests broadens the renderer class set"
|
||||
);
|
||||
|
||||
@@ -359,7 +359,7 @@ fn target_fetch_owner_keeps_fetch_enable_configs_per_session() {
|
||||
);
|
||||
assert_eq!(
|
||||
primary.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL,
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET),
|
||||
"session handleAuthRequests broadens the renderer class set"
|
||||
);
|
||||
|
||||
@@ -782,7 +782,7 @@ fn target_fetch_owner_reports_matching_auth_required_network_intercepts() {
|
||||
let config = owner.config_snapshot();
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert!(config.matches_auth_required(&matching_url));
|
||||
assert!(config.matches_auth_required(&other_url));
|
||||
@@ -851,7 +851,7 @@ fn cdp_auth_is_independent_of_network_intercept_registration() {
|
||||
assert!(config.matches_auth_required(&any_url));
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert!(owner.remove_network_intercept("intercept-no-auth"));
|
||||
assert!(owner.config_snapshot().matches_auth_required(&any_url));
|
||||
@@ -895,7 +895,7 @@ fn cdp_auth_is_independent_of_network_intercept_registration() {
|
||||
assert!(owner.config_snapshot().matches_auth_required(&any_url));
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
|
||||
owner.configure(Some("SID-other".to_owned()), false, image_patterns);
|
||||
@@ -915,11 +915,11 @@ fn cdp_auth_is_independent_of_network_intercept_registration() {
|
||||
snapshot.auth_required_owner_kind(&other_url),
|
||||
Some(PendingSubresourceFetchOwnerKind::NetworkOrBidi)
|
||||
);
|
||||
// A real auth rule still requires all resource classes even though it
|
||||
// A real auth rule still requires all HTTP resource classes even though it
|
||||
// no longer authorizes unrelated URLs after the last CDP handler stops.
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
assert!(owner.remove_network_intercept("intercept-auth"));
|
||||
assert_eq!(
|
||||
@@ -1965,7 +1965,7 @@ fn interception_eligibility_includes_authentication_independent_of_resource_type
|
||||
);
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
owner.configure(
|
||||
Some("CDP".to_owned()),
|
||||
@@ -1978,12 +1978,12 @@ fn interception_eligibility_includes_authentication_independent_of_resource_type
|
||||
);
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
owner.remove_fetch_session(Some("CDP"));
|
||||
assert_eq!(
|
||||
owner.subresource_interception_config(),
|
||||
SubresourceInterceptionClasses::ALL
|
||||
SubresourceInterceptionClasses::ALL.difference(SubresourceInterceptionClasses::WEBSOCKET)
|
||||
);
|
||||
owner.remove_network_intercept("auth");
|
||||
assert_eq!(
|
||||
|
||||
@@ -993,7 +993,7 @@ async fn enable_with_csp_violation_report_resource_type_filter_sets_csp_report_f
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn enable_with_websocket_resource_type_filter_sets_websocket_filter() {
|
||||
async fn enable_with_websocket_resource_type_filter_is_rejected() {
|
||||
let mut ctx = TestContext::new();
|
||||
{
|
||||
let fixture_value = Some(BrowserContext::new_with_page_for_test("BID-1", "TID-1"));
|
||||
@@ -1010,18 +1010,10 @@ async fn enable_with_websocket_resource_type_filter_sets_websocket_filter() {
|
||||
}
|
||||
}))
|
||||
.await;
|
||||
ctx.expect_result(20, json!({}), None);
|
||||
|
||||
ctx.expect_error(20, -32602, "InvalidParams");
|
||||
ctx.with_fixture(|conn| {
|
||||
let bc = conn.browser_context.as_ref().unwrap();
|
||||
assert!(bc.active_page_target().fetch_owner.is_enabled());
|
||||
assert_eq!(
|
||||
bc.active_page_target()
|
||||
.fetch_owner
|
||||
.config_snapshot()
|
||||
.resource_type_filter(),
|
||||
Some(FetchResourceTypeFilter::WebSocket)
|
||||
);
|
||||
assert!(!bc.active_page_target().fetch_owner.is_enabled());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -60,30 +60,6 @@ async fn with_loaded_http_document(
|
||||
});
|
||||
}
|
||||
|
||||
async fn with_loaded_http_background_document(
|
||||
ctx: &mut TestContext,
|
||||
url: &str,
|
||||
active_session_id: &str,
|
||||
active_target_id: &str,
|
||||
background_session_id: &str,
|
||||
background_target_id: &str,
|
||||
) {
|
||||
let background = PageTargetHost::with_url(
|
||||
background_target_id.to_owned(),
|
||||
Some(background_session_id.to_owned()),
|
||||
url.to_owned(),
|
||||
);
|
||||
|
||||
let mut bc = BrowserContext::new("BID-1".into());
|
||||
bc.set_active_target_id(active_target_id.to_owned());
|
||||
bc.attach_active_session(active_session_id.to_owned());
|
||||
bc.insert_page_target_host(background);
|
||||
ctx.with_fixture(|conn| conn.install_browser_context_fixture_for_test(bc));
|
||||
ctx.enable_page_events_for_test(Some(background_session_id));
|
||||
ctx.install_navigation_fixture_for_session_owner(url, Some(background_session_id))
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn loaded_page_html_for_test(ctx: &mut TestContext) -> String {
|
||||
ctx.serialize_fixture_document(None)
|
||||
.await
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -271,6 +271,12 @@ fn emit_complete_subresource_network_delivery_record(
|
||||
let initial_output_len = out.len();
|
||||
let request_id = delivery_output.request_id();
|
||||
let output = delivery_output.metadata();
|
||||
// The same native handshake record also feeds the dedicated WebSocket
|
||||
// delivery below. Publishing it as an ordinary HTTP request would give
|
||||
// clients an extra inflight request for a long-lived socket.
|
||||
if output.resource_type() == moli_core::page::SubresourceResourceType::WebSocket {
|
||||
return false;
|
||||
}
|
||||
let Some(runtime_slot) = conn.runtime_session_owner_slot_mut_for_owner(owner) else {
|
||||
return false;
|
||||
};
|
||||
@@ -289,16 +295,14 @@ fn emit_complete_subresource_network_delivery_record(
|
||||
if !runtime_slot.claim_completed_subresource_request_id(request_id) {
|
||||
return false;
|
||||
}
|
||||
if output.resource_type() != moli_core::page::SubresourceResourceType::WebSocket {
|
||||
record_subresource_pending_response_body(conn, owner, request_id, event_session_ids);
|
||||
record_subresource_request_body(
|
||||
conn,
|
||||
owner,
|
||||
request_id,
|
||||
output.request_body_bytes(),
|
||||
event_session_ids,
|
||||
);
|
||||
}
|
||||
record_subresource_pending_response_body(conn, owner, request_id, event_session_ids);
|
||||
record_subresource_request_body(
|
||||
conn,
|
||||
owner,
|
||||
request_id,
|
||||
output.request_body_bytes(),
|
||||
event_session_ids,
|
||||
);
|
||||
if !request_was_announced_by_fetch_pause {
|
||||
for event_session_id in event_session_ids {
|
||||
emit_request_will_be_sent(
|
||||
@@ -407,15 +411,13 @@ fn emit_complete_subresource_network_delivery_record(
|
||||
}
|
||||
}
|
||||
TargetSubresourceMetadataOutcome::Failure { error_text } => {
|
||||
if output.resource_type() != moli_core::page::SubresourceResourceType::WebSocket {
|
||||
record_subresource_failed_response_body(
|
||||
conn,
|
||||
owner,
|
||||
error_text.clone(),
|
||||
request_id,
|
||||
event_session_ids,
|
||||
);
|
||||
}
|
||||
record_subresource_failed_response_body(
|
||||
conn,
|
||||
owner,
|
||||
error_text.clone(),
|
||||
request_id,
|
||||
event_session_ids,
|
||||
);
|
||||
for event_session_id in event_session_ids {
|
||||
emit_loading_failed(
|
||||
out,
|
||||
|
||||
@@ -9,6 +9,65 @@ async fn enable_network_domain(ctx: &mut TestContext, id: u64, session_id: Optio
|
||||
ctx.expect_result(id, json!({}), session_id);
|
||||
}
|
||||
|
||||
async fn assert_blocked_websocket_events(ctx: &mut TestContext, url: &str) -> serde_json::Value {
|
||||
wait_until_messages(
|
||||
ctx,
|
||||
Some("SID-1"),
|
||||
"blocked WebSocket terminal",
|
||||
|messages| {
|
||||
let Some(created) = messages.iter().find(|message| {
|
||||
message["method"] == "Network.webSocketCreated" && message["params"]["url"] == url
|
||||
}) else {
|
||||
return false;
|
||||
};
|
||||
messages.iter().any(|message| {
|
||||
message["method"] == "Network.webSocketClosed"
|
||||
&& message["params"]["requestId"] == created["params"]["requestId"]
|
||||
})
|
||||
},
|
||||
)
|
||||
.await;
|
||||
let created = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.find(|message| {
|
||||
message["method"] == "Network.webSocketCreated" && message["params"]["url"] == url
|
||||
})
|
||||
.unwrap();
|
||||
let request_id = &created["params"]["requestId"];
|
||||
let events = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.filter(|message| &message["params"]["requestId"] == request_id)
|
||||
.collect::<Vec<_>>();
|
||||
let methods = events
|
||||
.iter()
|
||||
.map(|message| message["method"].as_str().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
methods,
|
||||
[
|
||||
"Network.webSocketCreated",
|
||||
"Network.webSocketWillSendHandshakeRequest",
|
||||
"Network.webSocketFrameError",
|
||||
"Network.webSocketClosed"
|
||||
]
|
||||
);
|
||||
assert!(events.iter().all(|message| message["sessionId"] == "SID-1"));
|
||||
assert_eq!(
|
||||
events[2]["params"]["errorMessage"],
|
||||
"net::ERR_BLOCKED_BY_CLIENT"
|
||||
);
|
||||
assert!(
|
||||
ctx.sent
|
||||
.iter()
|
||||
.all(|message| message["method"] != "Network.requestWillBeSent"
|
||||
|| (message["params"]["request"]["url"] != url
|
||||
&& message["params"]["type"] != "WebSocket"))
|
||||
);
|
||||
events[1]["params"]["request"].clone()
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn set_blocked_urls_requires_browser_context() {
|
||||
let mut ctx = TestContext::new();
|
||||
@@ -713,7 +772,7 @@ async fn set_blocked_urls_worker_xhr_emits_loading_failed() {
|
||||
assert_eq!(result["result"]["result"]["value"], "failed:0");
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn set_blocked_urls_worker_websocket_emits_loading_failed() {
|
||||
async fn set_blocked_urls_worker_websocket_emits_dedicated_failure_events() {
|
||||
let mut ctx = TestContext::new();
|
||||
let mut bc = BrowserContext::new("BID-1".into());
|
||||
bc.set_active_target_id("TID-1");
|
||||
@@ -800,50 +859,9 @@ async fn set_blocked_urls_worker_websocket_emits_loading_failed() {
|
||||
.find(|message| message["id"] == json!(2826))
|
||||
.cloned()
|
||||
.expect("runtime evaluate result");
|
||||
flush_until_subresource_failed(&mut ctx, "WebSocket", "blocked worker websocket failure").await;
|
||||
let failed = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.find(|message| message["method"] == json!("Network.loadingFailed"))
|
||||
.cloned()
|
||||
.expect("network loadingFailed event");
|
||||
assert_eq!(failed["sessionId"], "SID-1");
|
||||
assert_eq!(failed["params"]["type"], "WebSocket");
|
||||
assert_eq!(failed["params"]["errorText"], "net::ERR_BLOCKED_BY_CLIENT");
|
||||
let request_id = failed["params"]["requestId"]
|
||||
.as_str()
|
||||
.expect("failed request id");
|
||||
let request = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.find(|message| {
|
||||
message["method"] == json!("Network.requestWillBeSent")
|
||||
&& message["params"]["requestId"] == json!(request_id)
|
||||
})
|
||||
.expect("matching requestWillBeSent");
|
||||
assert_eq!(
|
||||
request["params"]["request"]["url"],
|
||||
"ws://example.test/blocked/worker-ws"
|
||||
);
|
||||
assert_eq!(
|
||||
request["params"]["request"]["headers"]["x-cdp-test"],
|
||||
"works-worker-ws"
|
||||
);
|
||||
ctx.complete_one_ready_scheduler_input_for_test().await;
|
||||
let worker_ws_failures = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.filter(|message| {
|
||||
message["method"] == json!("Network.loadingFailed")
|
||||
&& message["params"]["type"] == json!("WebSocket")
|
||||
&& message["params"]["errorText"] == json!("net::ERR_BLOCKED_BY_CLIENT")
|
||||
})
|
||||
.count();
|
||||
assert_eq!(worker_ws_failures, 1);
|
||||
assert!(ctx.sent.iter().any(|message| {
|
||||
message["method"] == json!("Network.webSocketCreated")
|
||||
&& message["params"]["url"] == json!("ws://example.test/blocked/worker-ws")
|
||||
}));
|
||||
let request =
|
||||
assert_blocked_websocket_events(&mut ctx, "ws://example.test/blocked/worker-ws").await;
|
||||
assert_eq!(request["headers"]["x-cdp-test"], "works-worker-ws");
|
||||
|
||||
ctx.process_and_wait_for_response_async(json!({
|
||||
"id": 2827,
|
||||
@@ -1191,7 +1209,7 @@ async fn set_blocked_urls_runtime_xhr_emits_loading_failed() {
|
||||
assert_eq!(result["result"]["result"]["value"], "failed:0");
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn set_blocked_urls_runtime_websocket_emits_loading_failed() {
|
||||
async fn set_blocked_urls_runtime_websocket_emits_dedicated_failure_events() {
|
||||
let mut ctx = TestContext::new();
|
||||
let mut bc = BrowserContext::new("BID-1".into());
|
||||
bc.set_active_target_id("TID-1");
|
||||
@@ -1257,28 +1275,7 @@ async fn set_blocked_urls_runtime_websocket_emits_loading_failed() {
|
||||
.find(|message| message["id"] == json!(2819))
|
||||
.cloned()
|
||||
.expect("runtime evaluate result");
|
||||
flush_until_subresource_failed(&mut ctx, "WebSocket", "blocked websocket failure").await;
|
||||
let failed = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.find(|message| {
|
||||
message["method"] == json!("Network.loadingFailed")
|
||||
&& message["params"]["type"] == json!("WebSocket")
|
||||
})
|
||||
.cloned()
|
||||
.expect("network loadingFailed event");
|
||||
assert_eq!(failed["sessionId"], "SID-1");
|
||||
assert_eq!(failed["params"]["errorText"], "net::ERR_BLOCKED_BY_CLIENT");
|
||||
let websocket_created = ctx
|
||||
.sent
|
||||
.iter()
|
||||
.find(|message| message["method"] == json!("Network.webSocketCreated"))
|
||||
.cloned()
|
||||
.expect("webSocketCreated event");
|
||||
assert_eq!(
|
||||
websocket_created["params"]["url"],
|
||||
"ws://example.test/blocked/socket"
|
||||
);
|
||||
assert_blocked_websocket_events(&mut ctx, "ws://example.test/blocked/socket").await;
|
||||
|
||||
ctx.process_async(json!({
|
||||
"id": 2820,
|
||||
|
||||
Reference in New Issue
Block a user