Javascript 将值插入到";表格;使用chrome扩展插件加载网页的
我对javascript和长话短说有些陌生,我正在尝试使用chrome扩展为我的学校登录页面构建自己的自动填充 在查看源代码并创建网页的html文件副本后,我发现用户名框ID为“username”,密码框ID为“password”(谁会猜到呢?),我在假html页面上运行了一个测试,并将它放入保存的密码和用户名中。然而,当我去尝试在铬扩展它不会工作 下面是我的清单和内容脚本的外观: 舱单:Javascript 将值插入到";表格;使用chrome扩展插件加载网页的,javascript,html,google-chrome,google-chrome-extension,Javascript,Html,Google Chrome,Google Chrome Extension,我对javascript和长话短说有些陌生,我正在尝试使用chrome扩展为我的学校登录页面构建自己的自动填充 在查看源代码并创建网页的html文件副本后,我发现用户名框ID为“username”,密码框ID为“password”(谁会猜到呢?),我在假html页面上运行了一个测试,并将它放入保存的密码和用户名中。然而,当我去尝试在铬扩展它不会工作 下面是我的清单和内容脚本的外观: 舱单: `content_scripts": [ { "run_at": "documen
`content_scripts": [
{
"run_at": "document_idle",
"matches": ["*://elearn.apsu.edu/*"],
"js": ["content.js"]
}
],
"permissions": [
"activeTab", "tabs", "http://elearn.apsu.edu/", "https://elearn.apsu.edu/"
]`
My content.js文件包含以下内容:
`window.onload = function(){
document.getElementById("Username").value = "*username*";
document.getElementById("Password").value = "*password*"; };`
我也尝试过这样设置我的content.js,但也没有成功:
`document.addEventListener('DOMContentLoaded', info, false);
info = function(){
document.getElementById("Username").value = "*username*";
document.getElementById("Password").value = "*password*";
};
`
有人有什么建议可以帮助您吗?您的内容脚本被注入
document\u idle
,这发生在DOMonload
事件之后(以及domcontentload
之后)。只需删除事件侦听器。另一个问题是动态构建的AJAX站点,可以通过MutationObserver或setInterval检查来解决。加载和执行扩展时,中到底显示了什么?我查看了控制台,发现唯一有用的是这个错误,它指向document.getElementById(“用户名”)上的my content.js.value行:“未捕获的TypeError:无法在window.onload(content.js:2)上将属性“value”设置为null”