Javascript 在Chrome扩展中编辑输入字段
我正在为我的一个项目开发一个chrome扩展,它需要测试网页的SQL注入漏洞。 到目前为止,我的扩展可以提取输入字段的数量,并将该数量打印回插件。 网上似乎没有关于如何以我需要的方式在线编辑DOM的信息。 这里有人能帮忙吗? 甚至只是让我的扩展能够将文本输入到输入字段 现在我知道,通过下面的内容,从内容脚本传递输入字段需要通过数组完成,这更像是一个概念 非常感谢 这是我的密码 清单:Javascript 在Chrome扩展中编辑输入字段,javascript,html,css,google-chrome,google-chrome-extension,Javascript,Html,Css,Google Chrome,Google Chrome Extension,我正在为我的一个项目开发一个chrome扩展,它需要测试网页的SQL注入漏洞。 到目前为止,我的扩展可以提取输入字段的数量,并将该数量打印回插件。 网上似乎没有关于如何以我需要的方式在线编辑DOM的信息。 这里有人能帮忙吗? 甚至只是让我的扩展能够将文本输入到输入字段 现在我知道,通过下面的内容,从内容脚本传递输入字段需要通过数组完成,这更像是一个概念 非常感谢 这是我的密码 清单: { "name": "SQL Injector", "ve
{
"name": "SQL Injector",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": [
"activeTab"
],
"browser_action": {
"default_popup": "html/homepage.html",
"default_title": "SQL Injector"
}
}
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
var textInputs;
var searchInputs;
var passwordInputs;
var emailInputs;
if (document.querySelectorAll)
{
textInputs = document.querySelectorAll('input[type=text]');
console.log(textInputs);
}
else
{
textInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'text')
{
textInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
searchInputs = document.querySelectorAll('input[type=search]');
console.log(searchInputs);
}
else
{
searchInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'search')
{
searchInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
passwordInputs = document.querySelectorAll('input[type=password]');
console.log(passwordInputs);
}
else
{
passwordInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'password')
{
passwordInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
emailInputs = document.querySelectorAll('input[type=email]');
console.log(emailInputs);
}
else
{
emailInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'email')
{
emailInputs.push(input);
}
}
}
var totalInputs = textInputs.length + searchInputs.length + passwordInputs.length + emailInputs.length;
sendResponse({count: totalInputs})
})
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, 'hi', setCount)
})
function setCount (res) {
document.getElementById("returnValue").innerHTML = `${res.count} total inputs on the page.`;
var items = [];
for(var i = 1; i <= res.count; i++) {
item = '<div class="ui input"><input type="text" placeholder="Input">';
items.push(item);
}
$('.searchfield').append(items.join("<br>"));
}
}, false)
SQL注入JS:
{
"name": "SQL Injector",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": [
"activeTab"
],
"browser_action": {
"default_popup": "html/homepage.html",
"default_title": "SQL Injector"
}
}
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
var textInputs;
var searchInputs;
var passwordInputs;
var emailInputs;
if (document.querySelectorAll)
{
textInputs = document.querySelectorAll('input[type=text]');
console.log(textInputs);
}
else
{
textInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'text')
{
textInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
searchInputs = document.querySelectorAll('input[type=search]');
console.log(searchInputs);
}
else
{
searchInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'search')
{
searchInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
passwordInputs = document.querySelectorAll('input[type=password]');
console.log(passwordInputs);
}
else
{
passwordInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'password')
{
passwordInputs.push(input);
}
}
}
if (document.querySelectorAll)
{
emailInputs = document.querySelectorAll('input[type=email]');
console.log(emailInputs);
}
else
{
emailInputs = [];
var unfiltered = document.getElementsByTagName("input"),
i = unfiltered.length,
input;
while(i--)
{
input = unfiltered[i];
if (!input.type || input.type === 'email')
{
emailInputs.push(input);
}
}
}
var totalInputs = textInputs.length + searchInputs.length + passwordInputs.length + emailInputs.length;
sendResponse({count: totalInputs})
})
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, 'hi', setCount)
})
function setCount (res) {
document.getElementById("returnValue").innerHTML = `${res.count} total inputs on the page.`;
var items = [];
for(var i = 1; i <= res.count; i++) {
item = '<div class="ui input"><input type="text" placeholder="Input">';
items.push(item);
}
$('.searchfield').append(items.join("<br>"));
}
}, false)
document.addEventListener('DOMContentLoaded',function(){
chrome.tabs.query({currentWindow:true,active:true},函数(tabs){
chrome.tabs.sendMessage(制表符[0].id,“hi”,setCount)
})
函数设置计数(res){
document.getElementById(“returnValue”).innerHTML=`${res.count}页面上的总输入量。`;
var项目=[];
对于(var i=1;i)您的内容脚本可以更改这些输入的值。请看哦,很好!我会看一看,谢谢!效果很好!谢谢。您可以在我的内容中看到,它所做的一切就是将总输入相加并发送到sqlinjection.js。我如何在sqlinjection.html中有一个按钮,然后调用内容来替换文本o指挥部?