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 4580348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:46:16+00:00 2026-05-21T20:46:16+00:00

Writing and reading from LocalStorage is working fine from my popup and tab. However,

  • 0

Writing and reading from LocalStorage is working fine from my popup and tab. However, when I attempt to add a value from my background page, it doesn’t seem to write at all. I’m viewing local storage in Chrome Developer Tools by refreshing and looking for the value to show.

In the following example code for background.html ‘lastId’ is displayed correctly in the alert when a new bookmark is added. However, the value is not stored. Additionally, the request for a known value appears to fail with no alert displaying. (Results are the same attempting both syntaxes shown below.)

<html>
<script>
// Grab the id of newly created bookmarks
chrome.bookmarks.onCreated.addListener(function(id) {
    var lastId = id;
    alert(lastId);
    localStorage['lastId'] = lastId;
            var testvalue = localStorage['309'];
    alert(testvalue);
            localStorage.setItem('lastId', lastId);
    var testvalue2 = localStorage.getItem('309');
    alert(testvalue2);
});
</script>
</html>

I keep thinking I must just be missing some small syntax issue or something but can’t see anything. If my manifest declaration was incorrect I don’t think the alert would work for the id. Stumped…

UPDATE: Turns out that you have to force reload of the extension on updates to background pages since they are persistent in browser memory when opened. That is why my saved code appeared not to work. It wasn’t refreshed and I am duly embarrassed.

  • 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-21T20:46:17+00:00Added an answer on May 21, 2026 at 8:46 pm

    Hm, I can think about couple things.

    You say that it works in a tab and a popup. This is very strange because it shouldn’t (if by tab you mean content script). Content scripts are able to access only localStorage that belongs to a site they are injected. Popup, background, option pages, and any othe page from extension’s folder can only access extension’s own localStorage. Those two local storages and completely separated. So maybe you are inspecting wrong localStorage?

    To see extension’s own localStorage you need to inspect background or popup page and check resources tab in the inspector. To inspect site or content script localStorage you need to open regular inspector on the page.

    Second moment is your localStorage assignment might be not what you are expecting.

    If you run:

    var lastId = 5;
    localStorage['lastId'] = lastId;
    

    you will get value 5 assigned to lastId property. So to read written value you need to run:

    alert(localStorage['lastId']); //not localStorage['5']
    

    If you want to store arrays then you would need to serialize/unserialize them through JSON as localStorage can store only strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am little confused... Is it true that reading\writing from several threads all except
I copy and paste code from this URL for creating and reading/writing a proc
I am using the excel pia's to do some writing and reading to/from excel
I'm getting data from a binary file, reading from file and writing in a
I'm running several scripts which are writing and reading from the same CSV file
I have an sqlite database I am writing and reading from. Most of the
am [writing reading] from a plain text file usernames and passwords, but its an
I have a parent class with methods for writing and reading it from the
I am launching many threads simultaneously, each one writing / reading data into/from a
I wrote a program which includes writing and reading from database. When I run

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.