0

I am building a Chrome Extension and in the main page (e.g index.html) I am downloading data that is saved like this

Json object:

return {
    Companies: dict, //dict is a HashMap
    totalCompanies: companies, //int
    totalEmployees: numEmployees, //int
};

this json can be pretty massive in size(because in the hashmap I save for each company an array of employees), how can I work with this json in a different page like Employees.html?

I mean index.html is the one downloading it, and I want to work with it on Employees.html.

Anonymous
  • 77
  • 1
  • 9
  • What do you mean by `HashMap` here, exactly? – Xan Jul 19 '16 at 17:02
  • it means in order to enumerate all Employees in all the companies you would have to for(var company in x.Companies) { var employeeArray = x.Companies[company]; .... } I know its not a HashMap, but the usage is similar the Comapny name is the key and the value is an array of strings of all the employees in that certain company – Anonymous Jul 19 '16 at 17:13
  • I was trying to use chrome.storage.sync set/get and it saves the int variables just fine but my "hashmap" is cleared? it says 0 in length. makes no sense? – Anonymous Jul 19 '16 at 18:19
  • 1. `sync` imposes severe limits on data size https://developer.chrome.com/extensions/storage#properties 2. Make sure you have a very firm grasp on [asynchronous JavaScript](http://stackoverflow.com/a/14220323/3959875) (feel free to find a better explanation) as this is how chrome.* API works. 3. Your question doesn't specify if those pages are internal to your extension (that is their url is `chrome-extension://`), whether `index.html` is a background page and so on. – wOxxOm Jul 19 '16 at 18:37
  • yes they are internal. I have a page used to download the data from some website. then I want in other pages to show just a list of employees for example. also I just found out you cant save associative array as json? that's why it doesn't save my array. so either I find a different way to save my data or somehow convert my array to json friendly – Anonymous Jul 19 '16 at 18:38
  • It's not clear why your object is not JSON-serializable. Show an example of it (maybe a screenshot of the object in devtools console). And what the maximum size can be. Ultimately, the choice is either using [a storage API](http://stackoverflow.com/a/34060802/3959875) or switching to SPA I think. – wOxxOm Jul 19 '16 at 18:45
  • ok after switching to chrome.storage.local it worked, the problem was I exceeded the sync limit which is much lower. but I am afraid soon I will run out of storage their aswell as I am limited to 5MB. I don't know what is SPA? will it allow me to save on bigger sizes? – Anonymous Jul 19 '16 at 19:13
  • 1. The [answer I've linked](http://stackoverflow.com/a/34060802/3959875) shows how to increase the storage quota. 2. [SPA stands for Single-Page Application](https://www.google.com/search?q=spa+javascript), so if everything is inside one page you won't need an intermediary storage. – wOxxOm Jul 19 '16 at 21:21

0 Answers0