@@ -15,6 +15,24 @@ import {
1515
1616const LOG = "[zotero-docling]" ;
1717
18+ /**
19+ * Diagnostic logger that emits to BOTH the Browser Toolbox console
20+ * (ztoolkit.log) AND Zotero's debug log (Zotero.debug). Lets the user see
21+ * diagnostic lines like "transport=async" without opening Help → Debug Output.
22+ */
23+ function log ( ...args : unknown [ ] ) : void {
24+ try {
25+ ztoolkit . log ( LOG , ...args ) ;
26+ } catch {
27+ /* ztoolkit not yet available */
28+ }
29+ try {
30+ Zotero . debug ( `${ LOG } ${ args . map ( ( a ) => String ( a ) ) . join ( " " ) } ` ) ;
31+ } catch {
32+ /* shutting down */
33+ }
34+ }
35+
1836/**
1937 * Z9's plugin sandbox exposes some Web APIs as bare globals (e.g. fetch) but
2038 * not others (e.g. FormData, Blob). Prefer bare globals when present, fall
@@ -346,7 +364,7 @@ async function fetchConvertResultAsync(
346364 if ( ! taskId ) {
347365 return { ok : false , message : "Async submit returned no task_id" } ;
348366 }
349- Zotero . debug ( ` ${ LOG } async task submitted id=${ taskId } `) ;
367+ log ( ` async task submitted id=${ taskId } `) ;
350368
351369 // 2. Poll until terminal
352370 const startMs = Date . now ( ) ;
@@ -408,7 +426,7 @@ async function fetchConvertResult(
408426 api : ReturnType < typeof getWebApis > ,
409427) : Promise < FetchOutcome > {
410428 const useAsync = ( getPref ( "useAsyncEndpoint" ) ?? false ) as boolean ;
411- Zotero . debug ( ` ${ LOG } transport=${ useAsync ? "async" : "sync" } `) ;
429+ log ( ` transport=${ useAsync ? "async" : "sync" } `) ;
412430 return useAsync
413431 ? fetchConvertResultAsync ( serverUrl , form , api )
414432 : fetchConvertResultSync ( serverUrl , form , api ) ;
@@ -481,7 +499,7 @@ export async function convertAttachment(
481499 }
482500
483501 // --- 6. Talk to docling-serve via sync or async transport ---
484- Zotero . debug ( ` ${ LOG } send ${ serverUrl } file=${ filename } `) ;
502+ log ( ` send ${ serverUrl } file=${ filename } `) ;
485503 const outcome = await fetchConvertResult ( serverUrl , form , api ) ;
486504 if ( ! outcome . ok ) {
487505 return { status : "error" , message : outcome . message } ;
0 commit comments