// Log when the worker is loaded to confirm it's running console.log('Worker script loaded'); // Function to handle messages sent to the worker onmessage = function(event) { console.log('Worker received message:', event.data); // Log when the worker receives a message if (event.data === 'fetch') { console.log('Worker is now fetching data...'); // Fetch data from the server fetch('/getguessednamepath/') .then((response) => { if (!response.ok) { console.error('Network response was not ok'); throw new Error('Network response was not ok'); } return response.json(); // Parse the response as JSON }) .then((data) => { console.log('Data fetched by worker:', data); // Log the fetched data postMessage({ status: 'success', data }); // Send the fetched data back to the main thread }) .catch((error) => { console.error('Error fetching data in worker:', error); // Log any errors in the worker postMessage({ status: 'error', error: error.message }); // Send error message back to the main thread }); } else { console.log('Unknown message received by worker:', event.data); // Log any unknown messages } };