From fb9d23c213e2cdfdeddb94ed66459cc13b5d339e Mon Sep 17 00:00:00 2001 From: Christopher Warner Date: Sat, 10 Oct 2026 19:02:13 -0400 Subject: fix(browser): invoke async NotesApp helpers as real JS functions chromiumoxide misclassifies `async () =>` as an expression, so create/update never ran. Use `async function ()` and wait for notes (not just folders). Co-authored-by: Cursor --- src/browser.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/browser.rs') diff --git a/src/browser.rs b/src/browser.rs index 2cecf5a..aee77ec 100644 --- a/src/browser.rs +++ b/src/browser.rs @@ -153,9 +153,11 @@ async fn notes_ready(page: &Page) -> Result { if (!dm) return { ready: false }; const notes = dm.allNotes || dm.__CW__allNotes; const folders = dm.allFolders || dm.__CW__allFolders || dm.folders; - const n = notes?.length || 0; - const f = folders?.length || 0; - return { ready: n > 0 || f > 0 }; + const n = (typeof notes?.get === "function" && typeof notes.get("length") === "number") + ? notes.get("length") + : (notes?.length || 0); + // Need at least one note so Note.create* is reachable via sample.constructor + return { ready: n > 0 }; }"#, ) .await? @@ -274,8 +276,10 @@ async fn create_via_notes_app(page: &Page, title: &str, body: &str) -> Result`) so chromiumoxide detects a JS + // function. Arrow form is misclassified as an expression and never invoked. let expr = format!( - r#"async () => {{ + r#"async function () {{ const text = {text_js}; const paras = {paras_js}; {helpers} @@ -335,8 +339,9 @@ async fn update_via_notes_app(page: &Page, match_title: &str, title: &str, body: let match_js = serde_json::to_string(match_title)?; let helpers = note_list_helpers_js(); let styles = style_helpers_js(); + // Use `async function ()` (not `async () =>`) — see create_via_notes_app. let expr = format!( - r#"async () => {{ + r#"async function () {{ const text = {text_js}; const matchTitle = {match_js}; {helpers} -- cgit v1.2.3