feat(callback_host): add use_hidden_domain param to bootstrap_helper_page
🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -25,7 +25,6 @@ const COMMANDS_ENDPOINT_PATH: &str = "/sgclaw/callback/commands/next";
|
|||||||
const COMMAND_ACK_ENDPOINT_PATH: &str = "/sgclaw/callback/commands/ack";
|
const COMMAND_ACK_ENDPOINT_PATH: &str = "/sgclaw/callback/commands/ack";
|
||||||
const COMMAND_POLL_INTERVAL: Duration = Duration::from_millis(25);
|
const COMMAND_POLL_INTERVAL: Duration = Duration::from_millis(25);
|
||||||
const HELPER_POLL_INTERVAL: Duration = Duration::from_millis(50);
|
const HELPER_POLL_INTERVAL: Duration = Duration::from_millis(50);
|
||||||
const HELPER_BOOTSTRAP_ACTION: &str = "sgBrowerserOpenPage";
|
|
||||||
const NAVIGATE_CALLBACK_NAME: &str = "sgclawOnLoaded";
|
const NAVIGATE_CALLBACK_NAME: &str = "sgclawOnLoaded";
|
||||||
const CLICK_PROBE_CALLBACK_NAME: &str = "sgclawOnClickProbe";
|
const CLICK_PROBE_CALLBACK_NAME: &str = "sgclawOnClickProbe";
|
||||||
const CLICK_CALLBACK_NAME: &str = "sgclawOnClick";
|
const CLICK_CALLBACK_NAME: &str = "sgclawOnClick";
|
||||||
@@ -48,6 +47,8 @@ pub(crate) struct LiveBrowserCallbackHost {
|
|||||||
server_thread: Mutex<Option<JoinHandle<()>>>,
|
server_thread: Mutex<Option<JoinHandle<()>>>,
|
||||||
command_lock: Mutex<()>,
|
command_lock: Mutex<()>,
|
||||||
result_timeout: Duration,
|
result_timeout: Duration,
|
||||||
|
browser_ws_url: String,
|
||||||
|
use_hidden_domain: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
@@ -217,6 +218,7 @@ impl LiveBrowserCallbackHost {
|
|||||||
bootstrap_request_url: &str,
|
bootstrap_request_url: &str,
|
||||||
ready_timeout: Duration,
|
ready_timeout: Duration,
|
||||||
result_timeout: Duration,
|
result_timeout: Duration,
|
||||||
|
use_hidden_domain: bool,
|
||||||
) -> Result<Self, PipeError> {
|
) -> Result<Self, PipeError> {
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").map_err(|err| {
|
let listener = TcpListener::bind("127.0.0.1:0").map_err(|err| {
|
||||||
PipeError::Protocol(format!("failed to bind callback host listener: {err}"))
|
PipeError::Protocol(format!("failed to bind callback host listener: {err}"))
|
||||||
@@ -238,7 +240,7 @@ impl LiveBrowserCallbackHost {
|
|||||||
let thread_shutdown = shutdown.clone();
|
let thread_shutdown = shutdown.clone();
|
||||||
let server_thread = thread::spawn(move || serve_loop(listener, thread_host, thread_shutdown));
|
let server_thread = thread::spawn(move || serve_loop(listener, thread_host, thread_shutdown));
|
||||||
|
|
||||||
bootstrap_helper_page(browser_ws_url, bootstrap_request_url, host.helper_url())?;
|
bootstrap_helper_page(browser_ws_url, bootstrap_request_url, host.helper_url(), use_hidden_domain)?;
|
||||||
wait_for_helper_ready(host.as_ref(), ready_timeout)?;
|
wait_for_helper_ready(host.as_ref(), ready_timeout)?;
|
||||||
|
|
||||||
let live_host = Self {
|
let live_host = Self {
|
||||||
@@ -247,6 +249,8 @@ impl LiveBrowserCallbackHost {
|
|||||||
server_thread: Mutex::new(Some(server_thread)),
|
server_thread: Mutex::new(Some(server_thread)),
|
||||||
command_lock: Mutex::new(()),
|
command_lock: Mutex::new(()),
|
||||||
result_timeout,
|
result_timeout,
|
||||||
|
browser_ws_url: browser_ws_url.to_string(),
|
||||||
|
use_hidden_domain,
|
||||||
};
|
};
|
||||||
Ok(live_host)
|
Ok(live_host)
|
||||||
}
|
}
|
||||||
@@ -337,7 +341,12 @@ fn normalize_loopback_origin(origin: &str) -> String {
|
|||||||
origin.trim_end_matches('/').to_string()
|
origin.trim_end_matches('/').to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bootstrap_helper_page(browser_ws_url: &str, request_url: &str, helper_url: &str) -> Result<(), PipeError> {
|
fn bootstrap_helper_page(
|
||||||
|
browser_ws_url: &str,
|
||||||
|
request_url: &str,
|
||||||
|
helper_url: &str,
|
||||||
|
use_hidden_domain: bool,
|
||||||
|
) -> Result<(), PipeError> {
|
||||||
let (mut websocket, _) = connect(browser_ws_url)
|
let (mut websocket, _) = connect(browser_ws_url)
|
||||||
.map_err(|err| PipeError::Protocol(format!("browser websocket connect failed: {err}")))?;
|
.map_err(|err| PipeError::Protocol(format!("browser websocket connect failed: {err}")))?;
|
||||||
configure_bootstrap_socket(&mut websocket)?;
|
configure_bootstrap_socket(&mut websocket)?;
|
||||||
@@ -347,9 +356,14 @@ fn bootstrap_helper_page(browser_ws_url: &str, request_url: &str, helper_url: &s
|
|||||||
))
|
))
|
||||||
.map_err(|err| PipeError::Protocol(format!("browser websocket register failed: {err}")))?;
|
.map_err(|err| PipeError::Protocol(format!("browser websocket register failed: {err}")))?;
|
||||||
let _ = recv_bootstrap_prelude(&mut websocket);
|
let _ = recv_bootstrap_prelude(&mut websocket);
|
||||||
|
let open_action = if use_hidden_domain {
|
||||||
|
"sgHideBrowerserOpenPage"
|
||||||
|
} else {
|
||||||
|
"sgBrowerserOpenPage"
|
||||||
|
};
|
||||||
let payload = json!([
|
let payload = json!([
|
||||||
request_url,
|
request_url,
|
||||||
HELPER_BOOTSTRAP_ACTION,
|
open_action,
|
||||||
helper_url,
|
helper_url,
|
||||||
])
|
])
|
||||||
.to_string();
|
.to_string();
|
||||||
@@ -1080,6 +1094,7 @@ mod tests {
|
|||||||
"https://www.zhihu.com",
|
"https://www.zhihu.com",
|
||||||
Duration::from_millis(100),
|
Duration::from_millis(100),
|
||||||
Duration::from_millis(50),
|
Duration::from_millis(50),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
assert!(result.is_err(), "expected timeout because no real helper page loads");
|
assert!(result.is_err(), "expected timeout because no real helper page loads");
|
||||||
drop(result);
|
drop(result);
|
||||||
@@ -1113,6 +1128,8 @@ mod tests {
|
|||||||
server_thread: Mutex::new(None),
|
server_thread: Mutex::new(None),
|
||||||
command_lock: Mutex::new(()),
|
command_lock: Mutex::new(()),
|
||||||
result_timeout: Duration::from_millis(10),
|
result_timeout: Duration::from_millis(10),
|
||||||
|
browser_ws_url: "ws://127.0.0.1:12345".to_string(),
|
||||||
|
use_hidden_domain: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = host.execute(BrowserCallbackRequest {
|
let response = host.execute(BrowserCallbackRequest {
|
||||||
|
|||||||
@@ -290,6 +290,7 @@ pub fn serve_client(
|
|||||||
&bootstrap_url,
|
&bootstrap_url,
|
||||||
Duration::from_secs(15),
|
Duration::from_secs(15),
|
||||||
BROWSER_RESPONSE_TIMEOUT,
|
BROWSER_RESPONSE_TIMEOUT,
|
||||||
|
false, // use_hidden_domain: visible tab for now
|
||||||
) {
|
) {
|
||||||
Ok(host) => {
|
Ok(host) => {
|
||||||
cached_host = Some(Arc::new(host));
|
cached_host = Some(Arc::new(host));
|
||||||
|
|||||||
Reference in New Issue
Block a user