google-chromegoogle-chrome-extensiongoogle-chrome-devtoolsautofill

Import autofill data from a file into Chrome


I have a CSV file of users (with email and name). Google Chrome stores its autofill data and you can add them manually here: chrome://settings/addresses

Is it possible to import the data automatically from the file?


Solution

  • The settings UI uses an internal API chrome.autofillPrivate.saveAddress (source).

    1. go to chrome://settings/addresses
    2. open devtools console
    3. paste and run the code below that adds an input button in the top right corner where you can select your CSV file: enter image description here
    for (const el of document.querySelectorAll('body > input'))
      el.remove();
    Object.assign(document.body.appendChild(document.createElement('input')), {
      type: 'file',
      style: 'position:absolute; top:2ex; right:0; z-index:999',
      onchange(e) {
        if (!this.files[0])
          return;
        const fr = new FileReader();
        fr.readAsText(this.files[0], 'UTF-8');
        fr.onload = () => {
    
          for (const line of fr.result.split(/\r?\n/)) {
            const [name, email] = line.split(',');
            chrome.autofillPrivate.saveAddress({
              emailAddresses: [email],
              fullNames: [name],
            });
          }
    
        };
        fr.onerror = console.error;
      },
    });