Utilize Chrome storage instead of localstorage to generate Parse sessions

I'm currently developing a Chrome Extension that relies on Parse User sessions. Because localstorage is limited to specific domains, I am looking to utilize chrome.storage so the data can be accessed across any site.

The existing Parse Javascript SDK uses localstorage for storing user objects and creating sessions. How can I modify this behavior to switch to using chrome.storage instead?

Here is my current approach:

on login
   store session token in chrome.storage

Then, during site visits:

if chrome.storage.sessiontoken
    create Parse session with the stored session token from chrome.storage

I'm trying to find a simpler solution, so if anyone has any suggestions, I'd appreciate it!

I wish I could just do: window.localstorage = chrome.storage

But I suspect that may cause issues. Has anyone found a way around this problem?

Answer №1

To effectively store data in a Chrome app using Parse, you'll need to create a custom storage controller utilizing the chrome API. This allows for a more efficient and non-blocking storage solution compared to the default window.localStorage API used by Parse.

Fortunately, Parse SDK is designed to support various types of storage (both synchronous and asynchronous) and enables users to set their own storage controller. Before initializing Parse, make sure to call

Parse.CoreManager.setStorageController(YOUR_STORAGE_CONTROLLER)
.

For example, you can refer to the Parse React Native storage controller on GitHub, which demonstrates an asynchronous storage approach:

  • A Sync controller object should have its async property set to 0 with functions like getItem, setItem,removeItem, and clear
  • An Async controller object should have its async property set to 1 with functions like
    getItemAsync, setItemAsync, removeItemAsync,
    and clear

Simply follow the example provided by Parse React Native to build your own custom storage controller using the chrome.storage API. This will enable Parse to utilize your controller instead of relying on localStorage.

For the original discussion on Github, visit: https://github.com/ParsePlatform/Parse-SDK-JS/issues/72

Answer №2

Substituting localstorage with chrome.storage directly is not possible due to their synchronous and asynchronous nature, as well as differences in API methods.

While it's not feasible to make the switch fully synchronous, there are some potential solutions:

  1. Handle storage operations in the background script where the domain for localStorage remains fixed.

  2. Create a local synchronous data copy of the storage like so:

    var localData = {};
    chrome.storage.local.get(null, function(data) {
      localData = data;
      doSomethingElse(); // This part is async
    })
    

    However, managing updates to this cache will pose challenges as you'll need to intercept writes and synchronize with chrome.storage, which may lead to asynchronous issues.

In essence, if a library utilizes localStorage internally, replacing it effectively without rewriting the library or utilizing the background context may prove difficult.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When utilizing the get method to invoke a JavaScript function, IE imposes a restriction of 2083 characters

I need assistance with passing a lengthy XML string to a JavaScript function. Currently, the process involves using an XSL file to generate HTML code which includes a link that triggers the function like this. <a href="javascript:myFunctionName('l ...

A guide on incorporating the close button into the title bar of a jQuery pop-up window

Check out this fiddle: https://jsfiddle.net/evbvrkan/ This project is quite comprehensive, so making major changes isn't possible. However, the requirement now is to find a way to place the close button for the second pop-up (which appears when you c ...

Verify whether an email is already registered in firestore authentication during the signup process using Angular

When a user signs up for our app, I want them to receive immediate feedback on whether the email they are attempting to sign up with already exists. Currently, the user has to submit the form before being notified if the email is taken or not. This desire ...

The methodology of executing a Javascript function

I have the following code snippet: (function() { $(document).ready(function() { //Event handlers $('.project-delete').on('click', function() { deleteProject($(this)); }); $('.keyword-delete').on(&ap ...

Extract the HTML table from Gmail and transfer it to Google Sheets with the help of Google Apps Script

Just dipping my toes into google apps script. On my to-do list is creating a script that can extract data from a table in Gmail and transfer it to Google Sheets. Here's an example of what the email body looks like: CONFIRMATION CODE GUEST&apo ...

Ways to verify the existence of a particular word within a nested array of objects

I have implemented a text input field and a send button for submitting the entered text. Utilizing the react-mention library, I am able to handle hashtags in the text. As the user types, if they include "#" it displays available hashtags from the data set. ...

Performing Jasmine unit testing on a component that relies on data from a service, which itself retrieves data from another service within an Angular 2+ application

Attempting to implement unit testing for a service using httpmock has been challenging. The service in question utilizes a method to make http get calls, but I have encountered difficulties in writing the test cases. saveservice.service.ts -- file const ...

Is there a way to transfer my existing Chrome profile to Selenium for testing purposes?

I am seeking a way to utilize Selenium in conjunction with my existing Chrome profile, even if it is currently being used. My goal is to initiate Selenium automation that can recognize any cookies set in my current Chrome session and have the ability to mo ...

Socket.io continuously refreshing and updating multiple instances

Incorporating socket.io into a small React application, I configured all the listeners within the "componentWillMount" method. See the code snippet below for reference: componentWillMount() { const socket = io(); socket.on('update', f ...

Enhance your Sails.js model by incorporating a custom instance method as a new property

As a JavaScript programmer still learning the ropes, I encountered a challenge while working with Sails.js and creating a model. Here is what I have so far: module.exports = { tableName: 'FOO_TABLE', attributes: { FOO: 'st ...

Using Backbone: Leveraging a custom extended model when fetching a collection

Currently, I am working on developing a custom Wordpress theme using technologies like Javascript, Requirejs, and Backbonejs. As part of this process, in the index route, I have set up a new postsCollection app.postsCollection = new Posts.Collection(); to ...

Run a PHP function using <button onclick=""> tag

Is it possible to trigger the execution of a PHP script when clicking an HTML button? I am aware that simply calling a PHP function directly from the button's onclick event like this: <button onclick="myPhpFunction("testString")">Button</butt ...

What's the reason for this Ajax request taking such a long time to display on the

My webpage features dynamic content created by Ajax, refreshing every 30 seconds with new information from the database. The PHP side of things seems to be functioning properly, but I suspect there might be an issue either in my JavaScript code or within t ...

When a user clicks on a React listItem, the information for that specific item is displayed using

As a beginner in the coding world, I am currently learning about React and JSON. My project involves working on three interconnected panels. Specifically, I aim to showcase checklist answers on the third panel. First Panel: Displaying: All the ESN ("46 ...

Angular confirmation page following successful HTTP POST request to Web API

First question here... I have been given the task of improving an Angular application, even though I am starting with zero experience in Angular. While I do have some background in JavaScript, I mostly work with Java (JSP's and yes, JavaScript). Despi ...

The issue arises when using an Angular directive with an input type set as "number"

When the input type is text, the code below works perfectly fine. However, it fails to function when the input type is changed to number. <div ng-app="myApp" ng-controller="myCtrl as model"> <input type="text" ng-model="cero" ng-decimal > ...

Is there a way to display a message in a div container instead of using the alert box when there is a successful ajax response?

Hey there, I'm currently working on implementing error validation handling for a custom form that I've created. I'm looking to display the error messages in a designated div rather than using the standard browser alert box. Since I'm fa ...

I am struggling to display an array of objects retrieved from the server in the UI using AngularJS

I am receiving an array of objects as a JSON from the server. When I try to access my service URI from HTML, I encounter the following array in my console: "angular.js:13920 Error: [$resource:badcfg] http://errors.angularjs.org/1.5.8/$resource/badcfg?p0= ...

Default scrollbars in Chrome are designed to seamlessly blend in

Recently, I established a Wordpress website and am aiming to incorporate custom scroll bars in specific divs. Utilizing the WP jScrollPane plugin has been effective except when viewed on Chrome using a Windows platform. A peculiar issue arises where the d ...

Tips for transforming the input date value from Mui Datepicker

import * as React from "react"; import moment from "moment"; import TextField from "@mui/material/TextField"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import { LocalizationProvider } from &quo ...