///|
/// Collect iframe src values from a context document.
fn BidiProtocol::collect_iframe_sources(
self : BidiProtocol,
ctx_id : String,
) -> Array[String] {
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
let runtime_sources = get_runtime_iframe_sources()
if runtime_sources.length() > 0 {
return runtime_sources
}
match self.manager.get_session(ctx_id) {
Some(session) => {
let doc = session.get_tree().get_document()
match session.get_tree().query_selector_all(doc, "iframe") {
Ok(nodes) => {
let sources : Array[String] = []
for node in nodes {
match session.get_tree().get_attribute(node, "src") {
Ok(Some(src)) => sources.push(src)
_ => sources.push("about:blank")
}
}
sources
}
Err(_) => []
}
}
None => []
}
}
///|
/// Collect inline script source texts from a context document.
fn BidiProtocol::collect_script_texts(
self : BidiProtocol,
ctx_id : String,
) -> Array[String] {
match self.manager.get_session(ctx_id) {
Some(session) => {
let doc = session.get_tree().get_document()
match session.get_tree().query_selector_all(doc, "script") {
Ok(nodes) => {
let scripts : Array[String] = []
for node in nodes {
match session.get_tree().get_text_content(node) {
Ok(text) => scripts.push(text)
Err(_) => ()
}
}
scripts
}
Err(_) => []
}
}
None => []
}
}