以前,用户Robin(谢谢)帮助我解决了代码中的一些打字错误。无论如何,当我点击按钮使代码工作时,它什么都不做。
我的错误在哪里?非常感谢你。
以下是代码:
的manifest.json
{
"name": "Bwin pages",
"version": "1.0",
"manifest_version": 2,
"description": "Open Bwin pages",
"background": {"scripts": ["background.js"]},
"browser_action": {"default_icon": "icon.gif"},
"permissions": ["tabs","activeTab","https://www.bwin.com"],
"content_scripts": [{
"matches": ["https://www.bwin.com/"],
"js": ["autofill.js"]
}],
"run_at": "document_end",
"all_frames": true
}
Background.js
console.log("Background.js Started .. ");
chrome.browserAction.onClicked.addListener(function (tab) {chrome.tabs.executeScript(tab.id, {file: 'autofill.js'});
console.log("Script Executed .. ");
});
Autofill.js
console.log("Autofill.js Started .. ");
var myUsername = "aaa";
var myPassword = "bbb";
var loginField = document.getElementById("ct106_ct107_loginview_baw_template_logincontrol_edtUsername");
var passwordField = document.getElementById("ct106_ct107_loginview_baw_template_logincontrol_edtPassword");
loginField.value = myUsername;
passwordField.value = myPassword;
var loginForm = document.getElementById ("ct106_ct107_loginview_baw_template_logincontrol_btnLogin");
loginForm.submit();
checkCookie();
答案 0 :(得分:0)
" content_script" section需要是一个对象数组,因为扩展可以包含多个匹配不同模式的内容脚本。
E.g。
"content_scripts": [{
"matches": ["https://www.bwin.com/"],
"js": ["autofill.js"]
}],