1

I'm trying to build an autofill extension but I don't know ho to use user input in my js fie. I tried with:

localStorage.setItem("full_name_E", full_name_E);

this is in the html script (popup for etension). And in the autofill js file I wrote:

localStorage.getItem('full_name_E');

but if I type the first command in the chrome console and refresh the page, full_name_E value appear in the box. I tried with import/export but it doesn't work. Any help?

IlTvrco
  • 23
  • 5

2 Answers2

2

You should use the Chrome storage API for this extension. It will allow you to let your users sync their autofill data to any browser they use.

chrome.storage.sync.set({key: value}, function() {
  console.log('Value is set to ' + value);
});

chrome.storage.sync.get(['key'], function(result) {
  console.log('Value currently is ' + result.key);
});

Add this to your manifest:

"permissions": [
    "storage"
  ],

You can find more information here: https://developer.chrome.com/docs/extensions/reference/storage/

Dan Mullin
  • 4,285
  • 2
  • 18
  • 34
  • thanks it works. But in your link they say "Warning Confidential user information should not be stored! The storage area isn't encrypted.". If i want to save card number or other confidential information, what do i have to use? – IlTvrco Apr 09 '21 at 15:19
  • True. There might be another method that is more secure. I’ll do some research on that. – Dan Mullin Apr 09 '21 at 15:21
1

localStorage is saving data on the "tab", so till you close the current tab, it will keep the data saved (even if you refresh the page).

It looks like you want to save a variable only for the current page, a classic variable should be enough.

Dharman
  • 30,962
  • 25
  • 85
  • 135