Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detect-autofill

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-autofill

Small javascript library to detect and even prevent browsers autofill of form elements. Usefull for implementing floating labels or applying custom logics/styles.

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
decreased by-2.25%
Maintainers
1
Weekly downloads
 
Created
Source

Detect browsers autofill

npm version Build Status David David Greenkeeper badge License: MIT

TLDR

  1. Import script in the head
<head>
  ...
  <script src="https://unpkg.com/detect-autofill/dist/detect-autofill.js"></script>
  ...
</head>
  1. add event listeners
  2. do your things...
document.addEventListener('onautocomplete', function(e) {
  e.target.hasAttribute('autocompleted'); // true or false
  e.preventDefault(); // prevent autocomplete
  // do you stuff...
})

Getting Started

Small javascript library to detect browser autofill of form elements. Usefull for implementing floating labels or appling custom styles.

Modern browsers all have some ability to autocomplete the forms in a web page. It can be a login or a registration form, and the autofill can be triggered automatiaclly by the browser or manually by the user. In both cases there is no native way to detect the autocomplete. This is where this small library comes in handy.

Every browser has it's own way to autocomplete a form. Basically this library creates and triggers a CustomEvent called autocomplete every time this happends.

Furthermore this custom event can be prevented like all native events in order to block browser autofill using e.preventDefault().

Features

  • Polyfill for CustomEvent integrated
  • CustomEvent on onautocomplete
  • CustomEvent on onautocomplete cancel
  • Possibility to prevent onautocomplete

Browser Support

CustomEventEdgeIE11ChromeFirefoxSafariOperaiOS
onautocomplete

* This script uses different technics to detect autofill based on the browser:

  • Chrome, Opera and Safari uses the pseudo-class :-webkit-autofill to trigger a custom animation.
  • Firefox uses input event on document and checks for a propriety inputType property of the event.
  • IE, Edge and iOS uses the same input event but they have to check the data property.
  • Android ha not yet been tested any help is welcomed.

Demos

The demos can be tested on every browser. If something is not working properly, please open an issue or a PR.

TitleSource codeLive demo
Fake login pageCodeLive

Keywords

FAQs

Package last updated on 07 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc