I want to load values from fill.js and when the anchor link in extension popup.html is clicked it will autofill form fields on a remote page that has field IDs of #user + #pw. This is what i currently have in my extension but i'm not sure if it's missing something in the manifest file or if back.js is needed.
fill.js
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === "fillFields") {
$("#user").val("name@email.com")
$("#pw").val("pass123")
}
});
popup.js
$("#fill").on("click", function(){
chrome.runtime.sendMessage({
action: 'fillFields'
});
});
popup.html
<!DOCTYPE html>
<html>
<head>
<title>Autofill</title>
<script src="jquery.js"></script>
<script src="popup.js"></script>
</head>
<a href="#" id="fill">Fill</a>
</body>
</html>
manifest.json
{
"manifest_version": 2,
"name": "Autofill",
"description": "",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Autofill",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
]
}
Remote form fields
<input name="user" type="text" id="user">
<input name="pw" type="text" id="pw">