Function goose_eggs::load_static_elements
source · pub async fn load_static_elements(user: &mut GooseUser, html: &str)
Expand description
Extract and load all local static elements from the the provided html.
While you can invoke this function directly, it’s generally preferred to invoke
validate_and_load_static_assets
which in turn invokes this function.
Example
use goose::prelude::*;
use goose_eggs::load_static_elements;
transaction!(load_page_and_static_elements).set_on_start();
async fn load_page_and_static_elements(user: &mut GooseUser) -> TransactionResult {
let mut goose = user.get("/").await?;
match goose.response {
Ok(response) => {
// Copy the headers so we have them for logging if there are errors.
let headers = &response.headers().clone();
match response.text().await {
Ok(html) => {
// Load all static elements on page.
load_static_elements(user, &html).await;
}
Err(e) => {
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(headers),
None,
);
}
}
}
Err(e) => {
return user.set_failure(
&format!("{}: no response from server: {}", goose.request.raw.url, e),
&mut goose.request,
None,
None,
);
}
}
Ok(())
}