I ran into this issue a while ago and if my memory is correct, the search only works when the book is hosted/published. For example, if you had it on Posit Connect , GitHub Pages, etc.
When you see the preview in the IDE it's like a "temporary publish" so the search works.
Correct. Browsers have a security feature now that requires JavaScript files to be loaded from the same domain or something like that. When you open a local file there is no domain, so some things don’t work.