fix: re-apply download behavior on recording context (#1019)
* fix: re-apply download behavior on recording context record start creates a new browser context via Target.createBrowserContext. Browser.setDownloadBehavior called at launch only applies to the default context, so downloads in the recording context are silently dropped. Fix: 1. Store download_path on BrowserManager (from LaunchOptions) 2. After creating the recording context, call Browser.setDownloadBehavior with the new browserContextId This ensures downloads work during recording. Fixes #1018 * fix: add download_path to third BrowserManager constructor (auto_connect_cdp)
This commit is contained in:
@@ -3489,6 +3489,25 @@ async fn handle_recording_start(cmd: &Value, state: &mut DaemonState) -> Result<
|
|||||||
let new_session_id = attach_result.session_id.clone();
|
let new_session_id = attach_result.session_id.clone();
|
||||||
mgr.enable_domains_pub(&new_session_id).await?;
|
mgr.enable_domains_pub(&new_session_id).await?;
|
||||||
|
|
||||||
|
// Re-apply download behavior to the recording context.
|
||||||
|
// Without this, downloads in the recording context are silently dropped
|
||||||
|
// because Browser.setDownloadBehavior at launch only applies to the default context.
|
||||||
|
if let Some(ref dl_path) = mgr.download_path {
|
||||||
|
let _ = mgr
|
||||||
|
.client
|
||||||
|
.send_command(
|
||||||
|
"Browser.setDownloadBehavior",
|
||||||
|
Some(json!({
|
||||||
|
"behavior": "allow",
|
||||||
|
"downloadPath": dl_path,
|
||||||
|
"browserContextId": context_id,
|
||||||
|
"eventsEnabled": true
|
||||||
|
})),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
// Transfer cookies to new context
|
// Transfer cookies to new context
|
||||||
if let Some(ref cr) = cookies_result {
|
if let Some(ref cr) = cookies_result {
|
||||||
if let Some(cookie_arr) = cr.get("cookies").and_then(|v| v.as_array()) {
|
if let Some(cookie_arr) = cr.get("cookies").and_then(|v| v.as_array()) {
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ pub struct BrowserManager {
|
|||||||
pages: Vec<PageInfo>,
|
pages: Vec<PageInfo>,
|
||||||
active_page_index: usize,
|
active_page_index: usize,
|
||||||
default_timeout_ms: u64,
|
default_timeout_ms: u64,
|
||||||
|
/// Stored download path from launch options, re-applied to new contexts (e.g., recording)
|
||||||
|
pub download_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const LIGHTPANDA_CDP_CONNECT_TIMEOUT: Duration = Duration::from_secs(5);
|
const LIGHTPANDA_CDP_CONNECT_TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
@@ -257,6 +259,7 @@ impl BrowserManager {
|
|||||||
pages: Vec::new(),
|
pages: Vec::new(),
|
||||||
active_page_index: 0,
|
active_page_index: 0,
|
||||||
default_timeout_ms: 25_000,
|
default_timeout_ms: 25_000,
|
||||||
|
download_path: download_path.clone(),
|
||||||
};
|
};
|
||||||
manager.discover_and_attach_targets().await?;
|
manager.discover_and_attach_targets().await?;
|
||||||
manager
|
manager
|
||||||
@@ -321,6 +324,7 @@ impl BrowserManager {
|
|||||||
pages: Vec::new(),
|
pages: Vec::new(),
|
||||||
active_page_index: 0,
|
active_page_index: 0,
|
||||||
default_timeout_ms: 10_000,
|
default_timeout_ms: 10_000,
|
||||||
|
download_path: None, // CDP connections don't have a launch-time download path
|
||||||
};
|
};
|
||||||
|
|
||||||
manager.discover_and_attach_targets().await?;
|
manager.discover_and_attach_targets().await?;
|
||||||
@@ -1252,6 +1256,7 @@ async fn initialize_lightpanda_manager(
|
|||||||
pages: Vec::new(),
|
pages: Vec::new(),
|
||||||
active_page_index: 0,
|
active_page_index: 0,
|
||||||
default_timeout_ms: 25_000,
|
default_timeout_ms: 25_000,
|
||||||
|
download_path: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
match discover_and_attach_lightpanda_targets(&mut manager, deadline).await {
|
match discover_and_attach_lightpanda_targets(&mut manager, deadline).await {
|
||||||
|
|||||||
Reference in New Issue
Block a user