Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:12:34+00:00 2026-05-26T09:12:34+00:00

I am still trying to save a user email entered in options.html to the

  • 0

I am still trying to save a user email entered in options.html to the extension_user variable in background.html as suggested in this answer. I hope someone can help.

In options page I have a textarea id="getEmail" that takes the user email and saves the entered email to localStorage:

//save entered gmail address
document.getElementById("save").addEventListener(
    "click", function ()
    {
        var user = document.getElementById("getEmail").value;
        localStorage.setItem("user", user);
        console.log("gmail id saved as " + user);
    } , false)

Now I want to pick up this email in background.html and save it as “extension_user”. In background.html I have

if (localStorage.getItem("user"))
{
    user = localStorage.getItem("user")
    //localStorage.clear()
    console.log("if(!user): " + user)
    //...    
    // run normal program
    //...
}
else
{
    chrome.tabs.create({url: "/options.html"});
    console.log("options page opened as new tab");
}

What happens is that background page sees the saved “user” only if I reload the extension after I saved the email in options page.

What am I missing?

And is it better to use message passing and send the user email saved in options directly to background page? I appreciate any suggestions to save this user email in background page permanently with or without localStorage. Thanks!

UPDATE by serg’s answer

background.html

function refreshUser ()
{
    user = localStorage.getItem("user");
    console.log("user inside of refreshUser function " + user);
}

user = localStorage.getItem("user");
if (!user)
{
    refreshUser(); 
    //user is not defined outside refreshUser()
    console.log("user outside of refreshUser function" + user);
    //run the rest of code here
    //...
}
else
{
    user = localStorage.getItem("user"); 
    console.log("this is the else close")
    //run the rest of code here
    //...

}

UPDATE

@serg I updated the code as follows but I still see that newUser is updated inside the function refreshUser() but it is null outside the function. What am I doing wrong?

newUser = localStorage.getItem("user");
console.log("first newUser " + newUser);
//newUser=null

function refreshUser() 
{
    newUser = localStorage.getItem("user");
    console.log("newUser inside of refreshUser function " + newUser);
    //newUser is updated with saved email in localStorage
}

console.log("newUser after refreshUser() " + newUser);
//newUser=null

Update

Following serg’s answer, this works:

function refreshUser () 
{
    newUser = localStorage.getItem("user");
}

...

formData.append("extension_user", newUser);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:12:35+00:00Added an answer on May 26, 2026 at 9:12 am

    Background page gets loaded when browser starts and remains loaded all the time. When you saved user inside options page, background page doesn’t know that localstorage value has changed, so you need to notify it somehow.

    The easiest approach would be calling some method inside background page once user is updated:

    //options
    localStorage.setItem("user", user);
    chrome.extension.getBackgroundPage().refreshUser();
    
    //bg page
    function refreshUser() {
        //user in localStorage is updated, read it
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still trying to figure this out from yesterday. I am trying to scroll an
I still am confused regarding Ajax technology. And I still cannot answer this question
I'm still learning what hibernate can do and this time i'm trying something that
Please help me with this hibernate problem, I'm new to hibernate and still trying
I'm trying to run a command as a different user and save the return
I am trying to save two models to the database. USER and BOARD. I
I'm trying to save an image like this (from an asp.net mvc application): public
I am trying to force a user to login once they call this update
I'm getting this error when trying to use form_for: _feedback_form.html.erb: <%= form_for @support, :html
This may be impossible, but I'm trying to save the state of my application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.