URL query parameters are meaningless to a browser, a browser only looks at Content-Type header from origin.
Route patterns may not contain any query parameters
For example, https://example.com/?anything is not a valid route pattern.
Cloudflare HTTP front end doesnt know what ‘?’ character is, you can’t include a ‘?’ in a route. Fix your JS code in the worker to not touch the response body if its html, or you need to separate API/JSON into a separate URL path ‘directory’ from HTML. Then you can use CF routes to never have HTML files go through the worker code. TBH, fix the JS code in your CFW to not manipulate HTML files (or any other unknown file types) instead of figuring out how not to have the worker be called in the first place. Performance/Quota should be the only reason a HTTP request skips your worker with a route pattern, not some kind of bug fix to the customer eyes by skipping the worker.
I will add that some API servers demand X-requested-with header or a special user agent to prove it’s XHR/fetch and not a navigate. Text/plain for all content unless otherwise whitelisted is a common generic security trend nowadays.