Skip to content

Commit

Permalink
chore(chrome): fix frame establishing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Sep 7, 2024
1 parent 949b91d commit dca3d09
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_examples"
version = "2.2.16"
version = "2.2.18"
authors = [
"j-mendez <[email protected]>",
]
Expand Down
2 changes: 1 addition & 1 deletion spider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider"
version = "2.2.16"
version = "2.2.18"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider/src/packages/scraper/element_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'a> ElementRef<'a> {
};
let mut buf = Vec::new();
match serialize(&mut buf, self, opts) {
_ => ()
_ => (),
};
crate::page::encode_bytes_from_language(&buf, "")
}
Expand Down
2 changes: 1 addition & 1 deletion spider/src/packages/scraper/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Html {
};
let mut buf = Vec::new();
match serialize(&mut buf, self, opts) {
_ => ()
_ => (),
};
crate::page::encode_bytes_from_language(&buf, "")
}
Expand Down
41 changes: 30 additions & 11 deletions spider/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,24 +841,40 @@ pub async fn fetch_page_html_chrome_base(
if !page_set {
// used for smart mode re-rendering direct assigning html
if content {
match page.set_content(source).await {
Ok(p) => {
valid = true;
p
match page.mainframe().await {
Ok(frame) => {
match page.execute(chromiumoxide::cdp::browser_protocol::page::SetDocumentContentParams {
frame_id: frame.unwrap_or_default(),
html: source.to_string()
}).await {
Ok(_p) => {
valid = true;
page
}
_ => page,
}
}
_ => {
match page.set_content(source).await {
Ok(p) => {
valid = true;
p
}
_ => page,
}
}
_ => page,
}
} else {
match perform_chrome_http_request(&page, source).await {
Ok(chqr) => {
match page.goto(source).await {
Ok(p) => {
valid = true;
chrome_http_req_res = chqr;
p
}
Err(e) => {
log("HTTP Error: ", e.to_string());
page
}
};
page
}
}
} else {
page
Expand Down Expand Up @@ -975,7 +991,10 @@ pub async fn fetch_page_html_chrome_base(
.await;
}

if !page_set && cfg!(feature = "cache_chrome_hybrid") {
if !page_set
&& cfg!(feature = "cache_chrome_hybrid")
&& chrome_http_req_res.status_code.is_success()
{
match url::Url::parse(source) {
Ok(u) => {
let http_response = HttpResponse {
Expand Down
4 changes: 1 addition & 3 deletions spider/src/website.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ async fn setup_chrome_interception_base(
}
}


/// Setup interception for chrome request. This does nothing without the 'chrome_intercept' flag.
#[cfg(all(feature = "chrome", not(feature = "chrome_intercept")))]
async fn setup_chrome_interception_base(
Expand All @@ -385,10 +384,9 @@ async fn setup_chrome_interception_base(
_ignore_visuals: bool,
_host_name: &str,
) -> Option<tokio::task::JoinHandle<()>> {
None
None
}


/// Semaphore low priority tasks to run
#[cfg(not(feature = "cowboy"))]
async fn run_task<F, Fut>(
Expand Down
2 changes: 1 addition & 1 deletion spider_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_cli"
version = "2.2.16"
version = "2.2.18"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_utils"
version = "2.2.16"
version = "2.2.18"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_worker"
version = "2.2.16"
version = "2.2.18"
authors = [
"j-mendez <[email protected]>"
]
Expand Down

0 comments on commit dca3d09

Please sign in to comment.