Having trouble with disabling auto complete in Angular? Wondering if it's feasible to adjust your browser settings to stop auto complete through JavaScript?

I've been trying to disable autocomplete by setting it to "false" ("/nope/no/new-password").

Even after attempting to use formControl and FormGroup along with a directive that sets the property to false using the native element, I still haven't found a solution to disable autocomplete/autofill.

Is there a way to change browser settings at the script level to turn off auto suggestions/autofill?

I've put in a lot of effort but haven't been successful. Below is the code I've used at both the form and directive levels:

<form [formGroup]="loginForm" autocomplete="off">
  <input matInput placeholder="Username" formControlName="username" autocomplete="off">
  <input matInput type="password" formControlName="password" autocomplete="new-password">
</form>
import { Directive, ElementRef } from '@angular/core';

@Directive({
  selector: '[autocompleteOff]'
})
export class AutocompleteOffDirective {
  constructor(private _el: ElementRef) {
    let w: any = window;
    let isChrome = w.chrome;
    if (isChrome) {
      this._el.nativeElement.setAttribute('autocomplete', 'off');
      this._el.nativeElement.setAttribute('autocorrect', 'off');
      this._el.nativeElement.setAttribute('autocapitalize', 'none');
      this._el.nativeElement.setAttribute('spellcheck', 'false');
    }
  }
}

Answer №1

It can be quite challenging to completely disable the, but there is a way to deactivate it with the use of off webauthn. Here's an example:

<input matInput type="password" formControlName="pwd" autocomplete="off webauthn">

Referenced from

Answer №2

It seems that modern browser developers strongly advocate for the use of password managers as the most secure strategy, making it impossible to disable them for an input of type=password. While it may be tempting to resist this trend and go against the norm, perhaps it's best to align with the majority and allow users to utilize a password manager. However, if you're feeling rebellious, you could create your own 'hidden' font and utilize type=text instead, as demonstrated in this answer:

The Mozilla documentation states:

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#the_autocomplete_attribute_and_login_fields

Browser-based password management is generally considered beneficial for security purposes, even without a master password. By relying on the browser to store passwords, users are more likely to choose stronger credentials than they would otherwise.

As a result, many modern browsers do not support autocomplete="off" for login fields:

If a site specifies autocomplete="off" for a form containing username and password input fields, the browser may still prompt the user to save the login information, autofilling the fields upon subsequent visits.

In Firefox (since version 38), Google Chrome (since version 34), and Internet Explorer (since version 11), setting autocomplete="off" for username and password fields may also lead to the browser offering to remember the login credentials.

In reality, users can easily circumvent autocomplete=off by downloading extensions, so the security value of setting it is questionable. Ultimately, it is up to the user whether they choose to have their credentials autofilled or not.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is preventing me from utilizing a dynamic import while working with Nuxt3?

I'm currently working on developing a component that allows me to dynamically import icons based on the provided icon name using unplugin-icons. However, I'm facing an issue where dynamic imports don't seem to work when the import path is dy ...

The filter becomes ineffective once I remove the input value

Check out this HTML table containing an input field that filters plans. https://i.stack.imgur.com/UfIw2.png I input the value => 1 The filter successfully works https://i.stack.imgur.com/CsQXh.png Removing the value (1) displays all recordings, tot ...

React is a powerful tool that allows for the dynamic changing of state within

Struggling with my first React app and trying to accomplish something basic. The Input component in my app has an array in state, which sends two numbers and a unique ID as an object to a parent Component when the array has two numbers entered. Sending t ...

Angular 8 feature module routing encompasses various components working together collaboratively

I am currently working on integrating a main module and a feature module that consists of various components. Below, I have provided the configuration for multiple routes within the feature routing file. const priorityRoutes: Routes = [ { path: &a ...

Tips for loading nested JSON data into an Angular Material dropdown list

My task involves extracting data from a JSON object and displaying the difficultyLevel. Despite several attempts, I have been unable to achieve the desired outcome. What changes should be made to the HTML file? const ELEMENT_DATA: data = { questions ...

At what stage in the code does the loop conclude?

While researching Selenium Webdriver framework best practices on GitHub, I came across the following code snippet: async function waitForVisible(driver, locator, retries = 3) { try { const element = await driver.findElement(locator); ...

Issue: Unable to access API target map in AGM using Google Map API

I attempted to integrate a Google map with multiple locations. While I was successful in using an Iframe for one location, I struggled to implement multiple locations within the Iframe. As a result, I tried utilizing AGM and used the same APIKey that I ha ...

Invoke a function within a JavaScript file from a separate file by utilizing a setTimeout method, all while incorporating the power of Angular

I've encountered an issue with my barcode scan detection code. Originally, the code was working fine when it was placed directly in an AngularJS controller. However, I needed to use the same code in another controller as well, so I moved the scan code ...

Checking for String Const Type in TypeScript

In my code, I have a custom type called Admin with two possible values: 'ADMIN' or 'AGENT'. There is a function that retrieves the user role from local storage: return localStorage.getItem('role'); I am looking to verify if ...

Sending parameters to ajax using a click event

I'm facing an issue with passing variables through Ajax to PHP. In a PHP file, I'm generating some divs with id and name attributes. livesrc.php echo "<div class=\"search-results\" id=\"" . $softwareArray['Sw_idn'] ...

Can a simultaneous read/write conflict occur in JavaScript while browsing?

A situation has arisen where I am executing multiple (let's say four) AJAX calls using AngularJS http get, and I desire each call to invoke a callback function that increments a counter. This way, I can track when all four threads have finished. I am ...

Error in TypeScript when accessing object using string variable as index

Currently, I am facing a challenge in my project where I am dynamically generating routes and managing them in an Elysia(~Express) application. The issue arises when TypeScript's type checking system fails to index an object using a string variable. S ...

Radio button is selected but textbox does not display

Struggling to get the radio button to display the textbox as intended, but unfortunately encountering issues. Here is the HTML code in the JSP page: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> ...

React - Object(...) is throwing an error because it is not a function or the value it is returning cannot be

I have encountered an issue with my React hook that wraps a class component. I am attempting to pass a state from this hook to the class component using useEffect, but I keep receiving the following error: TypeError: Object(...) is not a function or its r ...

Retrieve a value from a PHP database table and transfer it to a different PHP webpage

I have values retrieved from a database and I need to select a row from a table and pass those values to the next PHP page, OInfo.php. I attempted to use Javascript to place those values in textboxes, but upon clicking the continue button, the values are n ...

Guide on mocking a function inside another function imported from a module with TypeScript and Jest

I have a function inside the action directory that I want to test: import { Action, ActionProgress, ActionStatus, MagicLinkProgress } from '../../interfaces' import { areSameActions } from '../actionsProgress' export const findActionPr ...

Dynamic sidebar that adheres to the content and is placed alongside it using JavaScript

I am in need of creating a sticky sidebar that will float beside my content column. The purpose of this sidebar is to contain jump links on the page, similar to what can be seen on this page, but with the navigation buttons positioned directly next to the ...

Setting response character encoding in Node.js/Express - how is it done?

Assume I have the following code: app.get('/json', function(req, res) { res.set({ 'content-type': 'application/json' }).send('{"status": "0"}'); }); I've been attempting to send the response as ...

Identifying the presence of a tag in Vue.js

Check out my Code: <template v-for="day in getMonthLength()" > <td :id='notempty' v-for="dataa in data" v-if="dataa.employee_id === employee.id"> <input type="numb ...

An angular component that is functioning properly when connected to a live server, however, it is experiencing issues when trying to run `

I tried integrating versitka into my Angular component by placing the version HTML file and all necessary assets in the appropriate directories. However, when I run ng serve, only the HTML file seems to be working, while the CSS and images fail to load. I ...