【发布时间】:2020-06-25 10:03:54
【问题描述】:
我想做什么:
开发 chrome 扩展程序,在网站上提交表单(通过按钮单击事件)。表单的输入字段由 chrome 自动填充填充。为此,请使用带有内容脚本的声明性 js 注入。表单如下所示:
<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>
会发生什么:
页面已加载。这些值由 chrome 自动填充填充,人眼可见。但是,当我尝试使用 javascript 读取输入值时,它们是空的。 (因此,使用按钮提交表单会出错,因为这些值是“空的”。)一旦真正的用户与页面交互,这些值就可以在我的 javascript 中访问。
我对这个主题做了很多研究,包括以下内容:
这些线程都没有得出最终结论。
我尝试了一系列解决方案来模拟“真实的用户交互”以及其他变通方法。我试图用 js 键事件或鼠标事件来模拟真实的用户输入。我还尝试触发诸如 .blur()、.focus() ... 之类的事件。
是否可以在完全没有用户交互的情况下以任何方式读取自动填充的值?
实际上,获取由 chrome 自动填充填充的值就足够了。例如,直接从 chrome 密码存储中读取它们会很棒(我知道这是不可能的)。
谢谢, OliDev
【问题讨论】:
标签: javascript html google-chrome-extension autofill content-script