this repo has no description

feat: cross-origin library loading for interactive OCaml cells

Enable loading .cma.js files from a different origin (e.g., ocaml.org)
by working around Chrome's CORB which blocks cross-origin importScripts
for files with embedded binary CMI data.

worker.ml: detect cross-origin URLs in import_scripts and use
synchronous XHR + eval() instead of importScripts. Same-origin
URLs continue to use the standard path.

jtw_client.ml: create blob: URL wrapper for cross-origin worker.js
(browsers block cross-origin Worker construction), derive stdlib_dcs
URL from findlib_index base, switch to eval_stream for streaming
phrase-by-phrase output.

interactive_extension.ml: always load x-ocaml.js and worker.js from
local _x-ocaml/ path (same-origin), communicate universe URL via
<meta> tag. Set backend to "jtw" when a universe is configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+36 -1
+36 -1
lib/worker.ml
··· 61 61 let import_scripts urls = 62 62 (* Map relative URLs to absolute using the global base URL *) 63 63 let absolute_urls = List.map Jslib.map_url urls in 64 - Js_of_ocaml.Worker.import_scripts absolute_urls 64 + (* Chrome blocks cross-origin importScripts for .cma.js files (CORB). 65 + Work around this by fetching with sync XHR and eval'ing the code. *) 66 + let worker_origin = 67 + Js_of_ocaml.Js.Optdef.case 68 + (Js_of_ocaml.Js.Unsafe.js_expr "self.location.origin") 69 + (fun () -> "") 70 + Js_of_ocaml.Js.to_string 71 + in 72 + List.iter (fun url -> 73 + let is_cross_origin = 74 + worker_origin <> "" 75 + && String.length url > 8 76 + && (let prefix = 77 + try String.sub url 0 (String.index_from url 8 '/' + 1) 78 + with Not_found -> url 79 + in 80 + not (String.length prefix <= String.length worker_origin + 1 81 + && String.sub url 0 (String.length worker_origin) 82 + = worker_origin)) 83 + in 84 + if is_cross_origin then begin 85 + Jslib.log "Cross-origin import via fetch+eval: %s" url; 86 + match Jslib.sync_get url with 87 + | Some code -> 88 + let (_ : 'a) = 89 + Js_of_ocaml.Js.Unsafe.fun_call 90 + (Js_of_ocaml.Js.Unsafe.js_expr "eval") 91 + [| Js_of_ocaml.Js.Unsafe.inject 92 + (Js_of_ocaml.Js.string code) |] 93 + in 94 + () 95 + | None -> 96 + failwith (Printf.sprintf "Failed to fetch cross-origin script: %s" url) 97 + end else 98 + Js_of_ocaml.Worker.import_scripts [url] 99 + ) absolute_urls 65 100 let findlib_init = Findlibish.init async_get 66 101 67 102 let require b v = function