
Local storage in Chrome is a simple and powerful way to store data locally on a user's browser. It allows you to store key-value pairs, which can be accessed later.
Data stored in local storage is not sent to the server, making it a great option for storing user preferences or other non-sensitive information. This data is stored in a key-value pair format, where a key is associated with a specific value.
Local storage has a storage limit of 5MB per origin, which means that you can store up to 5MB of data for a particular website or application. This limit is set by the browser, and it's there to prevent abuse and ensure that users have a good experience.
You can store various types of data in local storage, including strings, integers, and even objects. For example, you can store a user's name and age as a string and integer, respectively.
On a similar theme: O Net Data
Creating and Editing

To create or edit localStorage key-value pairs in Chrome, you can follow these steps.
First, view a domain's localStorage key-value pairs by visiting a demo page. You can see a table of existing key-value pairs.
To create a new key-value pair, double-click the empty part of the table. DevTools will create a new row and focus your cursor in the Key column. Then, enter a new key-value pair.
Editing existing keys or values is just as easy. Simply double-click a cell in the Key or Value column to edit that key or value. Refresh the page to apply your changes.
Here's a quick summary of the steps:
- Create a new key-value pair by double-clicking the empty part of the table and entering a new key-value pair.
- Edit an existing key or value by double-clicking a cell in the Key or Value column.
- Refresh the page to apply your changes.
Managing Storage
Removing data from local storage is a crucial aspect of managing storage in Chrome extensions. You can use chrome.storage.local.remove to specify which key(s) you want to remove.
Chrome offers two functions to remove data: chrome.storage.local.remove and chrome.storage.local.clear. The first function lets you specify which key(s) you want to remove, while the second function clears all data stored in the extension's local storage.
Readers also liked: Traf O Data

Both functions have optional callback function parameters that will return on success or failure, and then runtime.lastError will be set. This is useful for error-catching.
In some cases, you might want to remove all the user's data once they log out of the app. You can use the clear function with an error-catching callback to achieve this.
Interacting with Storage
You can access localStorage from the Console in DevTools, which is a powerful tool for debugging and testing. Run your localStorage expressions in the Console, just like you would in your JavaScript.
To access localStorage key-value pairs from a different domain, select the JavaScript context you need from the context drop-down menu in the action bar at the top. This allows you to view and interact with storage from other domains.
To interact with localStorage from the Console, follow these steps:
- In DevTools, open the Console.
- Select the JavaScript context you need from the context drop-down menu in the action bar at the top.
- Run your localStorage expressions in the Console.
Delete Key-Value Pairs
To delete key-value pairs from localStorage, you can view a domain's key-value pairs in action.

You can do this by clicking a key-value pair to select it. Once selected, you can click Delete in the action bar at the top to remove the selected pair. Alternatively, you can click Clear all to remove all pairs.
If you want to delete multiple pairs at once, you can select multiple pairs by holding down the Ctrl key while clicking.
Interact with Console
You can run JavaScript in the Console and access the page's JavaScript contexts, allowing you to interact with localStorage.
To access localStorage from the Console, open the Console in DevTools.
If you want to access the localStorage key-value pairs of a domain other than the page you're on, select the JavaScript context you need from the context drop-down menu in the action bar at the top.
Run your localStorage expressions in the Console, the same as you would in your JavaScript.
Here's a step-by-step guide to interacting with localStorage from the Console:
- In DevTools, open the Console.
- Select the JavaScript context you need from the context drop-down menu in the action bar at the top.
- Run your localStorage expressions in the Console.
Storage Concepts
The Storage API provides an extension-specific way to persist user data and state, similar to the web platform's storage APIs.
All extension contexts, including the extension service worker and content scripts, have access to the Storage API.
The Storage API stores JSON serializable values as object properties and is asynchronous with bulk read and write operations.
Even if the user clears the cache and browsing history, the data persists, and stored settings persist even when using split incognito.
The chrome.storage API can be used to store, retrieve, and track changes to user data.
LocalStorage is similar to sessionStorage, but data stored in localStorage has no expiration time and is ideal for saving Chrome extension data.
LocalStorage is persistent among multiple page sessions, allowing users to click off and on the extension to their heart's content.
Here are the key features of the Storage API:
- All extension contexts have access to the Storage API.
- The Storage API stores JSON serializable values as object properties.
- The Storage API is asynchronous with bulk read and write operations.
- Data persists even if the user clears the cache and browsing history.
- Stored settings persist even when using split incognito.
- Includes an exclusive read-only managed storage area for enterprise policies.
Storage Limits and Permissions
To use the storage API in Chrome, you need to declare the "storage" permission in the extension manifest.
You should be careful about what data you store, as storing data often comes with performance costs and the API includes storage quotas.
Here are the storage usage limitations you should keep in mind:
- Storing data often comes with performance costs, and the API includes storage quotas.
- Storage can take time to complete, so make sure to structure your code to account for that time.
Limits
Storage limits are a crucial aspect to consider when working with the Storage API. Storing data often comes with performance costs, and the API includes storage quotas.
You'll want to be mindful of what data you store to avoid losing the ability to store data altogether. Storage can take time to complete, so make sure to structure your code to account for that time.
There are different types of storage quotas to be aware of, including sync, local, and session quotas. For more information on storage area limitations and what happens when they're exceeded, check out the quota information.
Here's a quick rundown of the types of quotas you'll need to consider:
- Sync quotas
- Local quotas
- Session quotas
Keep in mind that exceeding these quotas can have consequences, so it's essential to plan your storage strategy accordingly.
Permissions
To use the storage API, you need to declare the "storage" permission in the extension manifest. This is a crucial step to ensure your extension has the necessary access to storage.
The "storage" permission is declared in the extension manifest, as shown in the example: "For example:". It's essential to include this permission to avoid any issues with storage access.
To give you a better idea, let's take a look at the example: "Permissions / To use the storage API, declare the "storage" permission in the extension manifest." This is a straightforward way to ensure your extension has the necessary permissions.
By declaring the "storage" permission, you're giving your extension the access it needs to store and retrieve data. This is a fundamental aspect of working with the storage API.
If this caught your attention, see: Protonvpn Extension Chrome
Storage in Chrome Extensions
Storage in Chrome Extensions is a crucial aspect of building robust and user-friendly extensions. You can't use the Web Storage API in extension service workers, which means you need to find alternative solutions.
If you're using the Web Storage API in your extension, be aware that data saved using it is lost when the user clears their browsing history. This is a significant limitation, especially if you're storing sensitive user data.
To move data from web storage APIs to extension storage APIs, you can use an offscreen document and script file to perform the conversion. This involves creating a document, checking chrome.storage for your data, and sending a message to start the conversion routine.
Here's a summary of the key features of the Storage API:
- Accessible from all extension contexts, including service workers and content scripts.
- Stores JSON serializable values as object properties.
- Asynchronous with bulk read and write operations.
- Persistent even after clearing the cache and browsing history.
- Persistent even when using split incognito.
- Includes an exclusive read-only managed storage area for enterprise policies.
Chrome in Extension
Chrome provides its own storage API, chrome.storage, which offers the same storage capacity as the Web Storage API. This is a great option for extensions.
One thing to note is that chrome.storage is not encrypted, so it's not suitable for storing confidential customer data. This is something to keep in mind when implementing Chrome's storage in your extension.
Suggestion: Save Api Data on Local Storage Next Js
Extensions can use the Web Storage API in certain contexts, such as in popup and HTML pages. However, there are some limitations to consider.
Here are a few reasons why you might want to avoid using the Web Storage API in extensions:
- Extension service workers can't use the Web Storage API.
- Content scripts share storage with the host page.
- Data saved using the Web Storage API is lost when the user clears their browsing history.
If you're using a service worker and need to move data from the Web Storage API to chrome.storage, here's a step-by-step process you can follow:
1. Prepare an offscreen document HTML page and script file. The script file should contain a conversion routine and an onMessage handler.
2. In the extension service worker, check chrome.storage for your data.
3. If your data isn't found, call createDocument().
4. After the returned Promise resolves, call sendMessage() to start the conversion routine.
5. Inside the offscreen document's onMessage handler, call the conversion routine.
Intriguing read: Storage Service Provider
Manifest
The manifest file, also known as manifest.json, is a crucial part of your Chrome extension. It describes the app and provides important metadata.
The manifest file must declare the "storage" permission if you want to use chrome storage. This is a requirement, so don't forget to include it in your manifest.json file.
Chrome extensions have a unique manifest file that holds the app's metadata. This file is essential for the extension to function properly.
The manifest file contains information such as the app's name, scripts, permissions, and version. This information is vital for users to understand what the extension does and how it works.
In our extension, we made sure to include the "storage" permission in the manifest.json file. This allowed us to use chrome storage and store data locally.
Worth a look: Chrome Extension Devtools
Storage Areas and Types
Local storage in Chrome is divided into specific areas, each with its own purpose. The Storage API is the foundation of these areas.
The Storage API is divided into the following storage areas: local storage, session storage, and indexedDB. Local storage stores data even when the browser is closed, making it a great option for persistent data. Session storage, on the other hand, stores data only for the duration of the browsing session.
IndexedDB is a more advanced storage option that allows for structured data storage, making it ideal for complex applications.
Areas

Storage areas are divided into distinct categories to help you manage your data effectively.
The Storage API is divided into the following storage areas: local storage, session storage, and indexedDB.
Each storage area has its own strengths and weaknesses, making it essential to choose the right one for your application.
Local storage is ideal for storing small amounts of data that don't need to be synchronized across multiple devices.
Session storage is perfect for storing temporary data that needs to be deleted when the user closes their browser.
IndexedDB is a powerful storage option that allows for more complex data structures and larger storage capacity.
Type
Storage areas come in different types, each with its own limitations.
The QUOTA_BYTES10485760 type has a maximum storage limit of 10,485,760 bytes, which is the maximum amount of data that can be stored in local storage. This limit is measured by the JSON stringification of every value plus every key's length.
This value will be ignored if the extension has the unlimitedStorage permission. Updates that would cause this limit to be exceeded fail immediately.
If you're using a callback, a runtime.lastError will be set. If you're using async/await, the update will result in a rejected Promise.
Discover more: Google Chrome Local Storage Limit
Storage Sync and Preload

Storage Sync and Preload is a feature that allows you to store data locally on your device, syncing it with Chrome whenever you're connected to the internet. This can be especially useful for storing small amounts of data, such as user preferences or cached data.
The maximum number of items that can be stored in sync storage is 512, which is a relatively small limit, but sufficient for storing small amounts of data. This limit is enforced to prevent data from growing too large and overwhelming the storage system.
You can store up to 102400 bytes of data in sync storage, which is a significant amount, but still limited compared to other storage options. Each item in sync storage can be up to 8192 bytes in size, which is a relatively small limit.
Here's a summary of the storage limits for sync storage:
Respond To Updates
Respond to updates by adding a listener to the onChanged event of storage. This allows you to track changes made to storage.
The onChanged event fires whenever anything changes in storage. You can use this event to apply new settings as soon as possible.
The service worker uses storage.onChanged to apply the setting immediately after the user saves new settings to storage.sync.
Sync

Sync is a powerful tool that allows you to store and retrieve data across all your devices. The maximum number of items that can be stored in sync storage is 512.
Updates that would cause this limit to be exceeded will fail immediately and set runtime.lastError when using a callback, or when a Promise is rejected. You can store a lot of data in sync storage, with a maximum total amount of 102,400 bytes.
Each individual item in sync storage has a maximum size of 8,192 bytes, as measured by the JSON stringification of its value plus its key length. This means you can store a lot of small items, but larger items will fail to save.
The storage.sync API has several limits to prevent abuse and ensure a smooth user experience. Here are the limits:
These limits are in place to prevent abuse and ensure a smooth user experience.
Asynchronous Preload
Asynchronous preload is a technique used by Manifest V3 extensions to load data from storage before executing event handlers. This is necessary because service workers don't run all the time.
An async action.onClicked event handler can be used to wait for the storageCache global to be populated before executing its logic. This allows the extension to ensure that data is available before trying to use it.
Using asynchronous preload can help improve the performance and reliability of Manifest V3 extensions. By loading data from storage before executing event handlers, extensions can avoid errors and provide a better user experience.
Storage Examples and Parameters
The following samples demonstrate how to use local, sync, and session storage areas in Chrome. You can see examples of how data is stored and retrieved in these areas.
Local, sync, and session storage areas can be accessed using the following samples: local storage, sync storage, and session storage.
Here are the parameters for working with storage areas: callback function: The callback parameter is defined as (changes:object, areaName:string) =>void.
Examples
Let's explore some examples to help us better understand storage areas. The following samples demonstrate the local, sync, and session storage areas.

Local storage is a great place to store data that doesn't need to be synced across devices. It's like a personal notebook that only you can access.
Sync storage is perfect for data that needs to be shared across multiple devices, like a shared calendar.
Session storage is ideal for storing temporary data that's only needed for the duration of a user's session. This can be like a shopping cart that gets cleared when the user logs out.
These storage areas can be used in various ways to enhance user experience and improve application functionality.
Parameters
The callback parameter is a crucial part of storage examples, and it's essential to know how it works.
The callback parameter looks like this: (changes: object, areaName: string) => void. This tells us that it's a function that takes two parameters: changes and areaName.
The changes parameter is an object that contains the changes made to the storage. It's a key piece of information that helps us understand what's happening in the storage.
Worth a look: Object Storage Google
The areaName parameter is a string that represents the name of the area where the changes were made. This is useful for identifying where the changes occurred.
In some cases, the callback parameter might be used to handle errors or exceptions that occur during the storage process. It's a good idea to include error handling in your code to make it more robust.
Frequently Asked Questions
How do I turn on local storage in the browser?
To enable local storage in Google Chrome, toggle on the setting for "Allow sites to save and read cookie data" under "Cookies and site permissions". This will also allow third-party cookies, so you may want to consider adjusting the "Block third-party cookies" setting accordingly.
How do I clear local storage in Chrome?
To clear local storage in Chrome, press F12, navigate to the Storage section, and right-click your site to select Clear. This will delete local storage data for your website.
Featured Images: pexels.com


