Direct execution without daemon (fallback).
(cli: &Cli, ws_url: &str)
| 956 | |
| 957 | /// Direct execution without daemon (fallback). |
| 958 | async fn run_direct(cli: &Cli, ws_url: &str) -> Result<result::CommandResult> { |
| 959 | let mut client = cdp::CdpClient::connect(ws_url).await?; |
| 960 | |
| 961 | let is_browser = cli.is_browser_level(); |
| 962 | |
| 963 | if is_browser { |
| 964 | return match &cli.command { |
| 965 | Commands::ListPages => { |
| 966 | commands::pages::list_pages(&mut client, cli.output_format()).await |
| 967 | } |
| 968 | Commands::NewPage { |
| 969 | url, |
| 970 | viewport, |
| 971 | device_scale_factor, |
| 972 | mobile, |
| 973 | geolocation, |
| 974 | accuracy, |
| 975 | extra_headers, |
| 976 | } => { |
| 977 | let params = commands::emulation::EmulateParams { |
| 978 | viewport: viewport.clone(), |
| 979 | device_scale_factor: *device_scale_factor, |
| 980 | mobile: *mobile, |
| 981 | geolocation: geolocation.clone(), |
| 982 | accuracy: *accuracy, |
| 983 | clear_viewport: false, |
| 984 | clear_geolocation: false, |
| 985 | clear_all: false, |
| 986 | block_url: cli.block_url.clone(), |
| 987 | unblock_url: cli.unblock_url.clone(), |
| 988 | clear_blocks: false, |
| 989 | }; |
| 990 | params.validate()?; |
| 991 | |
| 992 | let params = if params.has_emulation() { |
| 993 | Some(params) |
| 994 | } else { |
| 995 | None |
| 996 | }; |
| 997 | commands::pages::new_page(&mut client, url, params, extra_headers.as_deref()).await |
| 998 | } |
| 999 | Commands::SwLogs { |
| 1000 | duration, |
| 1001 | extension_id, |
| 1002 | } => { |
| 1003 | commands::sw_logs::collect_sw_logs( |
| 1004 | &mut client, |
| 1005 | *duration, |
| 1006 | extension_id.as_deref(), |
| 1007 | cli.output_format(), |
| 1008 | ) |
| 1009 | .await |
| 1010 | } |
| 1011 | _ => unreachable!(), |
| 1012 | }; |
| 1013 | } |
| 1014 | |
| 1015 | let (target_id_arg, page_idx_arg) = match &cli.command { |
no test coverage detected