0
votes

What I am trying to do:

Developing a chrome extension, which submits a form (via a button click event) on a website. The form's input fields are filled by chrome autofill. For this is use declarative js-injection with content-scripts. The form looks like the following:

           <form action="...." method="post">
                <table style="margin-top:4px; margin-bottom:4px">
                    <tr>
                        <td width="40%">
                            <label for="username">Login:</label>
                        </td>
                        <td>
                            <input name="i_username" type="text" id="username" autocapitalize="off" value="" autofocus/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="password">Passwort:</label>
                        </td>
                        <td>
                            <input name="i_password" type="password" id="password"/>
                        </td>
                    </tr>

                    <tr>

                        <td>
                            <button type="submit" name="proceed" value="Login">Login</button>
                        </td>
                    </tr>
                </table>
            </form>

What does happen:

The page is loaded. The values are filled in by chrome autofill and are visible to the human eye. However, when I try to read the input values with javascript, they are empty. (And so submitting the form with the button gives an error, because the values are "empty".) As soon as the real user interacts with the page, the values are accessible within my javascript.

I did a lot of research on this topic, including the following:

Non of these threads reached a final conclusion.

I tried a range of solutions to simulate a 'real user-interaction' as well as other work-arounds. I tried to simulate real user input with js key-events or mouse-events. I also tried to trigger events like .blur(), .focus() ... .

Is it possible to read the values of autofill, without user interaction at all, in any way?

Actually it would be enough to get the values, which are filled by chrome autofill. For example, it would be great to read them from chrome password storage directly (, which i know is not possible).

Thanks, OliDev

1

1 Answers

1
votes

I am going to answer my own question:

There is a "isTrusted" property to each event: "The isTrusted read-only property of the Event interface is a Boolean that is true when the event was generated by a user action, and false when the event was created or modified by a script or dispatched via EventTarget.dispatchEvent()." (from https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted).

So it is NOT possible to simulate "real user input" with programmatic javascript-events. However, the autofilled values by chrome are only available, when there was a isTrusted=true event!

Note: although the window.scroll() event has isTrusted=true, it does not make the autofill values readable.