1/** 2 * Issues a same-origin XHR GET and resolves with the parsed JSON body. 3 * 4 * The site DNS-lookup endpoints gate on `request.xhr?`, so the request must 5 * carry the `X-Requested-With` marker; the JSON `Accept` header matches what the 6 * endpoints return. The promise rejects on a network failure or a non-2xx 7 * response so callers can treat both as a failed lookup. An empty or unparseable 8 * body on a 2xx response resolves to `undefined`. 9 * 10 * @param {string} url - The same-origin endpoint to query. 11 * @returns {Promise<*>} The parsed JSON body, or `undefined` when the body is 12 * empty or not valid JSON. 13 */ 14export const fetchJson = async (url) => { 15 const response = await fetch(url, { 16 headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, 17 credentials: 'same-origin' 18 }); 19 20 if (!response.ok) 21 throw new Error(`Request to ${url} failed with status ${response.status}`); 22 23 const text = await response.text(); 24 25 try { 26 return JSON.parse(text); 27 } catch (e) { 28 return undefined; 29 } 30};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.