File size: 751 Bytes
3d7d9b5
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use tauri::AppHandle;
use super::tab_manager::eval_on_tab;

/// Injects saved credentials into the active child webview's login form.
/// Called by the React frontend after user selects a credential from the vault.
/// Uses the __museAutofill() function that vault_detector.js defines in every page.
#[tauri::command]
pub fn tab_autofill(app: AppHandle, tab_id: String, username: String, password: String) -> Result<(), String> {
    let username_js = serde_json::to_string(&username).map_err(|e| e.to_string())?;
    let password_js = serde_json::to_string(&password).map_err(|e| e.to_string())?;
    let js = format!("window.__museAutofill && window.__museAutofill({username_js}, {password_js})");
    eval_on_tab(&app, &tab_id, &js)
}