Skip to content

Commit 8baaef4

Browse files
committed
chore: bump agent-browser version
1 parent 1124baf commit 8baaef4

File tree

2 files changed

+92
-33
lines changed

2 files changed

+92
-33
lines changed

Cargo.lock

Lines changed: 56 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/browser/engine.rs

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use browser_engine::native::snapshot::{self, SnapshotOptions};
2121
pub struct BrowserEngine {
2222
pub manager: BrowserManager,
2323
pub ref_map: RefMap,
24+
pub iframe_sessions: HashMap<String, String>,
2425
}
2526

2627
impl BrowserEngine {
@@ -32,6 +33,7 @@ impl BrowserEngine {
3233
Ok(Self {
3334
manager,
3435
ref_map: RefMap::new(),
36+
iframe_sessions: HashMap::new(),
3537
})
3638
}
3739

@@ -52,7 +54,7 @@ impl BrowserEngine {
5254
.manager
5355
.active_session_id()
5456
.map_err(|e| anyhow::anyhow!(e))?;
55-
snapshot::take_snapshot(client, session_id, &options, &mut self.ref_map)
57+
snapshot::take_snapshot(client, session_id, &options, &mut self.ref_map, None, &self.iframe_sessions)
5658
.await
5759
.map_err(|e| anyhow::anyhow!(e))
5860
}
@@ -118,8 +120,8 @@ impl BrowserEngine {
118120

119121
if new_tab {
120122
// Resolve element's href and open in new tab
121-
let object_id =
122-
element::resolve_element_object_id(client, session_id, &self.ref_map, selector)
123+
let (object_id, _effective_session) =
124+
element::resolve_element_object_id(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
123125
.await
124126
.map_err(|e| anyhow::anyhow!(e))?;
125127
let call_params = serde_json::json!({
@@ -160,6 +162,7 @@ impl BrowserEngine {
160162
selector,
161163
button.unwrap_or("left"),
162164
click_count.unwrap_or(1),
165+
&self.iframe_sessions,
163166
)
164167
.await
165168
.map_err(|e| anyhow::anyhow!(e))
@@ -168,7 +171,7 @@ impl BrowserEngine {
168171
/// Fill an input field (clears first, then inserts text).
169172
pub async fn fill(&self, selector: &str, value: &str) -> Result<()> {
170173
let (client, session_id) = self.active_client_and_session()?;
171-
interaction::fill(client, session_id, &self.ref_map, selector, value)
174+
interaction::fill(client, session_id, &self.ref_map, selector, value, &self.iframe_sessions)
172175
.await
173176
.map_err(|e| anyhow::anyhow!(e))
174177
}
@@ -190,6 +193,7 @@ impl BrowserEngine {
190193
text,
191194
clear,
192195
delay_ms,
196+
&self.iframe_sessions,
193197
)
194198
.await
195199
.map_err(|e| anyhow::anyhow!(e))
@@ -212,17 +216,17 @@ impl BrowserEngine {
212216
..SnapshotOptions::default()
213217
};
214218
let _ =
215-
snapshot::take_snapshot(client, session_id, &snap_opts, &mut self.ref_map).await;
219+
snapshot::take_snapshot(client, session_id, &snap_opts, &mut self.ref_map, None, &self.iframe_sessions).await;
216220
}
217-
screenshot::take_screenshot(client, session_id, &self.ref_map, &options)
221+
screenshot::take_screenshot(client, session_id, &self.ref_map, &options, &self.iframe_sessions)
218222
.await
219223
.map_err(|e| anyhow::anyhow!(e))
220224
}
221225

222226
/// Hover over an element.
223227
pub async fn hover(&self, selector: &str) -> Result<()> {
224228
let (client, session_id) = self.active_client_and_session()?;
225-
interaction::hover(client, session_id, &self.ref_map, selector)
229+
interaction::hover(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
226230
.await
227231
.map_err(|e| anyhow::anyhow!(e))
228232
}
@@ -237,6 +241,7 @@ impl BrowserEngine {
237241
selector,
238242
delta_x,
239243
delta_y,
244+
&self.iframe_sessions,
240245
)
241246
.await
242247
.map_err(|e| anyhow::anyhow!(e))
@@ -245,7 +250,7 @@ impl BrowserEngine {
245250
/// Select dropdown option(s).
246251
pub async fn select(&self, selector: &str, values: &[String]) -> Result<()> {
247252
let (client, session_id) = self.active_client_and_session()?;
248-
interaction::select_option(client, session_id, &self.ref_map, selector, values)
253+
interaction::select_option(client, session_id, &self.ref_map, selector, values, &self.iframe_sessions)
249254
.await
250255
.map_err(|e| anyhow::anyhow!(e))
251256
}
@@ -261,23 +266,23 @@ impl BrowserEngine {
261266
/// Check a checkbox.
262267
pub async fn check(&self, selector: &str) -> Result<()> {
263268
let (client, session_id) = self.active_client_and_session()?;
264-
interaction::check(client, session_id, &self.ref_map, selector)
269+
interaction::check(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
265270
.await
266271
.map_err(|e| anyhow::anyhow!(e))
267272
}
268273

269274
/// Uncheck a checkbox.
270275
pub async fn uncheck(&self, selector: &str) -> Result<()> {
271276
let (client, session_id) = self.active_client_and_session()?;
272-
interaction::uncheck(client, session_id, &self.ref_map, selector)
277+
interaction::uncheck(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
273278
.await
274279
.map_err(|e| anyhow::anyhow!(e))
275280
}
276281

277282
/// Get the text content of an element.
278283
pub async fn get_text(&self, selector: &str) -> Result<String> {
279284
let (client, session_id) = self.active_client_and_session()?;
280-
element::get_element_text(client, session_id, &self.ref_map, selector)
285+
element::get_element_text(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
281286
.await
282287
.map_err(|e| anyhow::anyhow!(e))
283288
}
@@ -289,31 +294,31 @@ impl BrowserEngine {
289294
attribute: &str,
290295
) -> Result<serde_json::Value> {
291296
let (client, session_id) = self.active_client_and_session()?;
292-
element::get_element_attribute(client, session_id, &self.ref_map, selector, attribute)
297+
element::get_element_attribute(client, session_id, &self.ref_map, selector, attribute, &self.iframe_sessions)
293298
.await
294299
.map_err(|e| anyhow::anyhow!(e))
295300
}
296301

297302
/// Check if an element is visible.
298303
pub async fn is_visible(&self, selector: &str) -> Result<bool> {
299304
let (client, session_id) = self.active_client_and_session()?;
300-
element::is_element_visible(client, session_id, &self.ref_map, selector)
305+
element::is_element_visible(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
301306
.await
302307
.map_err(|e| anyhow::anyhow!(e))
303308
}
304309

305310
/// Check if an element is enabled.
306311
pub async fn is_enabled(&self, selector: &str) -> Result<bool> {
307312
let (client, session_id) = self.active_client_and_session()?;
308-
element::is_element_enabled(client, session_id, &self.ref_map, selector)
313+
element::is_element_enabled(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
309314
.await
310315
.map_err(|e| anyhow::anyhow!(e))
311316
}
312317

313318
/// Check if a checkbox/radio is checked.
314319
pub async fn is_checked(&self, selector: &str) -> Result<bool> {
315320
let (client, session_id) = self.active_client_and_session()?;
316-
element::is_element_checked(client, session_id, &self.ref_map, selector)
321+
element::is_element_checked(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
317322
.await
318323
.map_err(|e| anyhow::anyhow!(e))
319324
}
@@ -444,71 +449,71 @@ impl BrowserEngine {
444449
/// Double-click an element.
445450
pub async fn dblclick(&self, selector: &str) -> Result<()> {
446451
let (client, session_id) = self.active_client_and_session()?;
447-
interaction::dblclick(client, session_id, &self.ref_map, selector)
452+
interaction::dblclick(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
448453
.await
449454
.map_err(|e| anyhow::anyhow!(e))
450455
}
451456

452457
/// Focus an element.
453458
pub async fn focus(&self, selector: &str) -> Result<()> {
454459
let (client, session_id) = self.active_client_and_session()?;
455-
interaction::focus(client, session_id, &self.ref_map, selector)
460+
interaction::focus(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
456461
.await
457462
.map_err(|e| anyhow::anyhow!(e))
458463
}
459464

460465
/// Clear an input field.
461466
pub async fn clear(&self, selector: &str) -> Result<()> {
462467
let (client, session_id) = self.active_client_and_session()?;
463-
interaction::clear(client, session_id, &self.ref_map, selector)
468+
interaction::clear(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
464469
.await
465470
.map_err(|e| anyhow::anyhow!(e))
466471
}
467472

468473
/// Select all text in an input.
469474
pub async fn select_all(&self, selector: &str) -> Result<()> {
470475
let (client, session_id) = self.active_client_and_session()?;
471-
interaction::select_all(client, session_id, &self.ref_map, selector)
476+
interaction::select_all(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
472477
.await
473478
.map_err(|e| anyhow::anyhow!(e))
474479
}
475480

476481
/// Scroll an element into view.
477482
pub async fn scroll_into_view(&self, selector: &str) -> Result<()> {
478483
let (client, session_id) = self.active_client_and_session()?;
479-
interaction::scroll_into_view(client, session_id, &self.ref_map, selector)
484+
interaction::scroll_into_view(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
480485
.await
481486
.map_err(|e| anyhow::anyhow!(e))
482487
}
483488

484489
/// Get inner text of an element.
485490
pub async fn inner_text(&self, selector: &str) -> Result<String> {
486491
let (client, session_id) = self.active_client_and_session()?;
487-
element::get_element_inner_text(client, session_id, &self.ref_map, selector)
492+
element::get_element_inner_text(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
488493
.await
489494
.map_err(|e| anyhow::anyhow!(e))
490495
}
491496

492497
/// Get inner HTML of an element.
493498
pub async fn inner_html(&self, selector: &str) -> Result<String> {
494499
let (client, session_id) = self.active_client_and_session()?;
495-
element::get_element_inner_html(client, session_id, &self.ref_map, selector)
500+
element::get_element_inner_html(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
496501
.await
497502
.map_err(|e| anyhow::anyhow!(e))
498503
}
499504

500505
/// Get the value of an input/textarea.
501506
pub async fn input_value(&self, selector: &str) -> Result<String> {
502507
let (client, session_id) = self.active_client_and_session()?;
503-
element::get_element_input_value(client, session_id, &self.ref_map, selector)
508+
element::get_element_input_value(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
504509
.await
505510
.map_err(|e| anyhow::anyhow!(e))
506511
}
507512

508513
/// Set the value of an input (without events).
509514
pub async fn set_value(&self, selector: &str, value: &str) -> Result<()> {
510515
let (client, session_id) = self.active_client_and_session()?;
511-
element::set_element_value(client, session_id, &self.ref_map, selector, value)
516+
element::set_element_value(client, session_id, &self.ref_map, selector, value, &self.iframe_sessions)
512517
.await
513518
.map_err(|e| anyhow::anyhow!(e))
514519
}
@@ -524,7 +529,7 @@ impl BrowserEngine {
524529
/// Get the bounding box of an element.
525530
pub async fn bounding_box(&self, selector: &str) -> Result<serde_json::Value> {
526531
let (client, session_id) = self.active_client_and_session()?;
527-
element::get_element_bounding_box(client, session_id, &self.ref_map, selector)
532+
element::get_element_bounding_box(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
528533
.await
529534
.map_err(|e| anyhow::anyhow!(e))
530535
}
@@ -536,7 +541,7 @@ impl BrowserEngine {
536541
properties: Option<Vec<String>>,
537542
) -> Result<serde_json::Value> {
538543
let (client, session_id) = self.active_client_and_session()?;
539-
element::get_element_styles(client, session_id, &self.ref_map, selector, properties)
544+
element::get_element_styles(client, session_id, &self.ref_map, selector, properties, &self.iframe_sessions)
540545
.await
541546
.map_err(|e| anyhow::anyhow!(e))
542547
}
@@ -733,10 +738,10 @@ impl BrowserEngine {
733738
/// Drag and drop from one element to another.
734739
pub async fn drag(&self, source: &str, target: &str) -> Result<()> {
735740
let (client, session_id) = self.active_client_and_session()?;
736-
let src_box = element::get_element_bounding_box(client, session_id, &self.ref_map, source)
741+
let src_box = element::get_element_bounding_box(client, session_id, &self.ref_map, source, &self.iframe_sessions)
737742
.await
738743
.map_err(|e| anyhow::anyhow!(e))?;
739-
let tgt_box = element::get_element_bounding_box(client, session_id, &self.ref_map, target)
744+
let tgt_box = element::get_element_bounding_box(client, session_id, &self.ref_map, target, &self.iframe_sessions)
740745
.await
741746
.map_err(|e| anyhow::anyhow!(e))?;
742747

@@ -802,8 +807,8 @@ impl BrowserEngine {
802807
/// Upload files to a file input element.
803808
pub async fn upload_files(&self, selector: &str, files: &[String]) -> Result<()> {
804809
let (client, session_id) = self.active_client_and_session()?;
805-
let object_id =
806-
element::resolve_element_object_id(client, session_id, &self.ref_map, selector)
810+
let (object_id, _effective_session) =
811+
element::resolve_element_object_id(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
807812
.await
808813
.map_err(|e| anyhow::anyhow!(e))?;
809814
client
@@ -822,7 +827,7 @@ impl BrowserEngine {
822827
/// Visually highlight an element.
823828
pub async fn highlight(&self, selector: &str) -> Result<()> {
824829
let (client, session_id) = self.active_client_and_session()?;
825-
interaction::highlight(client, session_id, &self.ref_map, selector)
830+
interaction::highlight(client, session_id, &self.ref_map, selector, &self.iframe_sessions)
826831
.await
827832
.map_err(|e| anyhow::anyhow!(e))
828833
}

0 commit comments

Comments
 (0)