# autofill-js

> Autofill form inputs during development and test

Latest version **2.0.5** (published 2026-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install autofill-js
pnpm add autofill-js
yarn add autofill-js
bun add autofill-js
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2026-08-21 |
| First published | 2022-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 320.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | 0kyn |
| Maintainers | okn |
| Keywords | js, autofill, form, input |

## Links

- npm: https://www.npmjs.com/package/autofill-js
- Repository: https://github.com/0kyn/autofill-js
- Homepage: https://github.com/0kyn/autofill-js#readme
- Issues: https://github.com/0kyn/autofill-js/issues
- npm.io page: https://npm.io/package/autofill-js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.5 (latest) — 2026-08-21
- 2.0.4 — 2026-03-08
- 2.0.2 — 2025-09-25
- 2.0.0 — 2025-03-23
- 1.2.4 — 2023-02-21
- 1.2.2 — 2023-01-28
- 1.2.1 — 2022-12-20
- 1.1.8 — 2022-12-18
- 1.1.7 — 2022-12-16
- 1.1.5 — 2022-12-12
- 1.1.3 — 2022-09-07
- 1.1.2 — 2022-08-16
- 1.1.1 — 2022-08-05
- 1.0.6 — 2022-08-04
- 1.0.5 — 2022-08-04

## README

# Autofill.js

Autofill.js is a tiny JavaScript library that autofills forms inputs with specific or random values. It might help you during development and form testing.

## Quickest start

If you already have a HTML form you just need to add the snippet below

```html
<script src="https://cdn.jsdelivr.net/npm/autofill-js@2.0.5/dist/js/autofill.min.js"></script>
<script>autofill()</script>
```

[Zero Config example](https://0kyn.github.io/autofill-js/examples/zero-config/index.html)

## Quick Start

1. Include script from jsDelivr CDN

```html
<script src="https://cdn.jsdelivr.net/npm/autofill-js@2.0.5/dist/js/autofill.min.js"></script>
```

2. Get a simple HTML form

```html
<form>
  <input type="text" name="username">
  <input type="email" name="email">
  <input type="password" name="password">

  <select name="selectMultiple" multiple>
    <option value="">Choose locations</option>
    <option value="UKNW">Unknown</option>
    <option value="OCN">Ocean</option>
    <option value="MTN">Mountain</option>
    <option value="PLCE">Place</option>
  </select>

  <input type="checkbox" name="checkboxes[opt1]" value="option1">
  <input type="checkbox" name="checkboxes[opt2]" value="option2">
  <input type="checkbox" name="checkboxes[opt3]" value="option3">
</form>
```

3. Init Autofill.js

This should generates random or/and preset value for every form(s) inputs present in the HTML DOM

```html
<script>
  (async() => {
    await autofill()

    console.log('form inputs filled')
  })()
</script>
```

You might also specify arbitrary values

```javascript
autofill({
  inputs: {
    // username: 'jdoe', // input is not defined so it lets it empty
    email: 'john@doe.com',
    selectMultiple: ['UKNW', 'PLCE'],
    checkboxes: ['option1', 'option2'], // as for selectMultiple you can check inputs by values
    // checkboxes: [0, 1], // or by index position (result is the same as above)
  }
})
```
## Configuration

Below the default Autofill.js config

```javascript
defaultConfig = {
  // enable autofill
  enable: true,

  // display an overlay with config infos & reset/autofill buttons
  overlay: false,

  // JSON config file url
  url: false,

  // form query selector
  formsSelectors: ['form'],

  // generated value must be valid according to inputs attributes
  validateInputAttributes: ['minlength', 'maxlength'],

  // emit submit event after form's inputs filling
  autosubmit: false,

  // e.g. allow input property 'inputName' to handle 'input-name' or 'input_name'
  camelize: false,

  // trigger events after value set
  events: ['input', 'change'],

  // generate random value where an input's value is formatted as follow {{ password|len?:16 }}
  generate: false,

  // input key attributes targets ordered from the highest priority to the lowest
  inputAttributes: ['data-autofill', 'name', 'id', 'class'],

  // skip autofilling when input has specific attribute. e.g. 'disabled' or 'readonly',
  inputAttributesSkip: [],

  // skip autofilling when input has specific type
  inputTypesSkip: [],

  // inputs support
  inputsSelectors: ['input', 'textarea', 'select', 'progress', 'meter'],

  // override already defined input value
  override: false,

  // if an input value is not defined it fills with a random value
  random: false,

  // if random === true && randomPreset === true then it tries to find a significant preset
  randomPreset: false,

  // handle value in html attribute
  valueAttribute: true,
}
```

> If you need to set specific value (e.g. old input error handling), you might switch `override` to `false`


## Examples

- Handle specific forms

```js
autofill({
  // display an overlay with config infos & reset/autofill buttons
  overlay: true,

  // will generate random values for every undefined input
  random: true,

  // generate string based on definition {{ password|len:16 }} => w{Ck.-FcUvg5!,-@
  generate: true,
  forms: {
    'form#formId, form.formClasses': {
      inputs: {
        email: 'john@doe.com',
        password: '{{ password|len:16 }}'
      }
    }
  }
})

```

- Multiple forms independently

```js
autofill({
  generate: true,
  forms: {
    '#formId': {
      autosubmit: true, // it will autosubmit this form after autofilling
      generate: false,
      inputs: {
        email: 'john@doe.com',
        password: '{{ password|len:16 }}' // display raw text as generate === false for this specific form
      },
    },
    'form.formClasses': {
      email: 'john@do3.com',
      password: '{{ password|len:100 }}' // generates a password
    }
  }
})

```

- Events dispatch

```js
autofill({
  events: ['change', 'input'], // dispatch events once input value set
  inputs: {
    username: 'jdoe', // trigger 'change' & 'input'
    email: {
      events: ['click'],
      value: 'john@doe.com' // trigger only 'click'
    },
    password: 'S3cUrEd', // trigger 'change' & 'input'
  }
})

```

- JSON Configuration

```js
autofill({ url: 'https://link.to/file.json' })

```
[JSON Config example](https://0kyn.github.io/autofill-js/examples/json/index.html)

## Sandbox

You can try out Autofill.js on [CodePen](https://codepen.io/0kyn/pen/ZExroMb)

## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/autofill-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
