【发布时间】:2014-04-16 04:48:29
【问题描述】:
到目前为止,我在弄清楚我的代码出了什么问题时遇到了问题,因为当我单击该图标时,它说我同时运行了 background.js 和 autofill.js。但不会自动填充 gmail 站点。这是我的第一个 chrome 扩展以及使用 javascript。我的最终目标是它可以自动填充所有网站(不仅仅是 gmail)并能够存储/读取 .txt 文件中的所有密码。另一件事是,当我尝试运行此代码时,说我的 autofill.js 文件有问题,并给我错误“未捕获的 TypeError:无法设置属性‘值’为 null。这是针对 autofill.js 的评论 //填写您的用户名和密码。 感谢您抽出宝贵时间帮助我,任何意见都会对我有所帮助,因为我被卡住了,碰壁了
manifest.json:
{
"name": "Test",
"manifest_version": 2,
"version": "1.0",
"description": "This is a Chrome extension that will autofill passwords",
"browser_action": {
"default_icon": "icon.png",
"default_popup":"popup.html",
"default_title": "PasswordFill"
},
//*********************************************************************
//declaring the permissions that will be used in this extension
"permissions": ["*://*.google.com/", "tabs", "activeTab", "*://*.yahoo.com/"],
"background": {
"scripts": ["background.js", "autofill.js"]
},
//*********************************************************************
/* Content scripts are JavaScript files that run in the context of web pages. By using the standard Document Object Model (DOM), they can read details of the web pages the browser visits, or make changes to them */
"content_scripts": [
{
//Specifies which pages this content script will be injected into
"matches": ["https://accounts.google.com/ServiceLoginAuth"],
//The list of JavaScript files to be injected into matching pages
"js": ["autofill.js"], //was background.js
//Controls when the files at "js" are being injected
"run_at": "document_end",
"all_frames": true
}
]
}
background.js:
console.log("Background.js Started .. "); //for debug purpose so i can see it in the console log
chrome.browserAction.onClicked.addListener(function (tab) { //Starts when User Clicks on ICON
chrome.tabs.executeScript(tab.id, {file: 'autofill.js'});
console.log("Script Executed .. "); // Notification on Completion
});
自动填充.js:
console.log("Autofill.js Started .. "); //for debug purpose so i can see it in the console log
//define username and password
var myUsername = 'McAfee.sdp';
var myPassword = 'baskin310';
//finds the fields in your login form
var loginField = document.getElementById('Email');
var passwordField = document.getElementById('Passwd');
//fills in your username and password
loginField.value = myUsername;
passwordField.value = myPassword;
//automatically submits the login form
var loginForm = document.getElementById ('signIn');
loginForm.submit();
【问题讨论】:
-
你发现问题了吗? @user3409109
标签: javascript google-chrome google-chrome-extension autofill password-encryption