Browser (JavaScript)

Important: The native EventSource API does not support custom headers. To authenticate from the browser, you must either:

Proxy requests through your own backend that injects the Authorization header

Native EventSource (requires proxy or query-param auth)

const eventSource = new EventSource(
  '/api/v1/scan-url?url=https://seranking.com&lang=en'
);

eventSource.addEventListener('progress', (e) => {
  const data = JSON.parse(e.data);
  console.log(`[${data.percent}%] ${data.current_task}`);
});

eventSource.addEventListener('result', (e) => {
  const data = JSON.parse(e.data);
  console.log('Result:', data);
  eventSource.close();
});

eventSource.addEventListener('error', (e) => {
  if (e.data) {
    const data = JSON.parse(e.data);
    console.error('Scan error:', data.error_message);
  }
  eventSource.close();
});

Last updated