-1

I'm trying to fill inputs on https://account.protonmail.com/login with javascript.

First navigate to https://account.protonmail.com/login and run the following javascript in devtools:

document.querySelector('#username').value = 'MyUser'
document.querySelector('#password').value = 'MyPassword'

And the form is filled:

enter image description here

But when I click on "Sign in", the values are gone:

enter image description here

How can I keep the values when I click on "Sign in"?

5
  • It does work, jsfiddle.net/41qgt39v/1, so the problem is elsewhere Commented Jun 14, 2021 at 14:41
  • 1
    @JaredFarrish You don't understand this question and you haven't run the same test as I did. Commented Jun 14, 2021 at 14:44
  • try triggering oninput or onchange to run whatever is setting the values elsewhere Commented Jun 14, 2021 at 14:46
  • You mean you didn't adequately explain the issue. Commented Jun 14, 2021 at 14:47
  • @JaredFarrish see if it's clear by now Commented Jun 14, 2021 at 14:50

1 Answer 1

4

The Proton Account page you linked is based on React, according to its source code. React (like many other frameworks) listens for specific events to know whether or not a user has changed values in form fields.

Fortunately, answerers in another SO thread were able to leverage a simple function for this same functionality, which you can re-use to complete the fields and trigger the appropriate events & validation logic. Your code would look something like this:

function changeValue(input,value){

    var nativeInputValueSetter = Object.getOwnPropertyDescriptor(
      window.HTMLInputElement.prototype,
      "value"
    ).set;
    nativeInputValueSetter.call(input, value);

    var inputEvent = new Event("input", { bubbles: true });
    input.dispatchEvent(inputEvent);
}

changeValue(document.querySelector('#username'), 'MyUser');
changeValue(document.querySelector('#password'), 'MyPassword');

This allows the field validation to be passed for me when running this code in the developer console within the latest release of Chrome.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.