This question already has an answer here:
I'm trying to build a chrome extension in which I have to store some data locally. Code given below is my popup.html and I can't understand why this doesn't set values in local storage. My manifest.json has "storage" and "tabs" permission.
<script type="text/javascript">
function save() {
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
chrome.storage.local.set({'username': username}, function(){});
chrome.storage.local.set({'password': password}, function(){});
}
</script>
Roll Number
<input type="text" name="username" id="username"></input>
Password
<input type="password" name="password" id="password"></input>
<button onclick="save()" type="submit" name="submit">Save</button>
This is my manifest.json file.
{
"manifest_version": 2,
"name": "Autologin",
"description": "Blah bhla.",
"version": "1.0",
"permissions": [
"http://xxxxxxxxxxxxx/*",
"storage"
],
"content_scripts": [
{
"matches": ["http://xxxxxxxxxxxxx/*"],
"js": ["autologin.js"]
}
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "autologin.html"
}
}
Try this, It worked for me
var dataObj = {}; dataObj[username] = username; dataObj[password] = password; chrome.storage.local.set(dataObj, function() {});
You need to move the script part out of html by creating a
popup.js
and include it in your html.In popup.js
In popup.html
Replace that bunch of
<script>...</script>
as<script src=popup.js></script>
In manifest.json