joelpt / sidewise

Persistent sidebar extension for Chrome featuring tree style tabs and tab hibernation.
Creative Commons Zero v1.0 Universal
68 stars 13 forks source link

Import does not work #83

Open Klausthorn opened 4 years ago

Klausthorn commented 4 years ago

Open Options, Reveal advanced options, Export Data, Import Data

" There was a problem importing the data.

Unexpected token u in JSON at position 1422

SyntaxError: Unexpected token u in JSON at position 1422 at JSON.parse () at Settings.importFromJSON (chrome-extension://biiamm[...]go/js/util/settings.js:116:25) [...]"

mcpower commented 4 years ago

Replace this function in js/util/utils.js:

function mapObjectProps(a,c){var b=[],d;for(d in a){var e=c(d,a[d]);void 0!==e&&b.push(e)}return b}

with

function mapObjectProps(a,c){var b=[],d;for(d in a){if (!a.hasOwnProperty(d)) {continue};var e=c(d,a[d]);void 0!==e&&b.push(e)}return b}

Follow the instructions in this comment to apply the patch, or you can download the .zip which includes the above patch.


All patches in this comment are released into the public domain and is free from copyright. Original code is copyright (c) 2012 Joel Thornton sidewise@joelpt.net. If you distribute this patch, attribution is not required, although it would be appreciated 😄

Klausthorn commented 4 years ago

Thanks! but the error is still the same.

I am trying to import the data that I exported with the unpatched sidewise, by the way.

Is there additional info I can help you with?

mcpower commented 4 years ago

The problem is that when exporting data, Sidewise accidentally exports "too much" data, including the length of localstorage as well as some functions associated with it (which can't be exported to JSON). This results in a broken JSON export.

If you have a broken export, you can fix it by doing the below steps (be sure to make a backup of your export before modifying it!)

  1. Delete the broken function exports. These look like ,"key": function key() { [native code] }, where "key" is the name of the function. My export has these function names, all close together in the export:

    • key
    • getItem
    • setItem
    • removeItem
    • clear in that order. Your export should have the exact same functions, although there's a small chance that you may have more or less functions. Delete all these functions. In my case, I had to delete this exact string from my JSON export:
      ,"key": function key() { [native code] },"getItem": function getItem() { [native code] },"setItem": function setItem() { [native code] },"removeItem": function removeItem() { [native code] },"clear": function clear() { [native code] }

      You may need to delete more or less functions. Ensure that no occurrences of [native code] appear in your export after you're done.

  2. Delete the length key. Search for this string inside your export, including the leading comma and trailing colon: ,"length":. You should find something like ,"length": 37, which should be right before the functions you deleted. This length number may change between exports - mine is 37, yours may be different. Delete the entire thing, starting from the comma, ending at the number. In my case, I deleted this exact string from my JSON export:

    ,"length": 37

The above process can be automated and be done automatically whenever someone tries to import a broken export, but that requires more code than the simple patches that I've been sharing. When I make a fork of Sidewise (soon!) I'll implement auto-fixing of broken exports on import 😄

Edit: My Sidewise fork can import these broken exports without any user modification!

NorseGaud commented 3 years ago

Hey @mcpower, would you mind opening some PRs for all of your fixes into https://github.com/joelpt/sidewise now that the code has been made open source by Joel? I know he and I would appreciate it :)

mcpower commented 3 years ago

@NorseGaud Unfortunately, my employer doesn't allow me to submit PRs to this repo (due to licensing issues) 😢

Feel free to cherry pick my commits though! I give everyone full permission to take any commits made in my fork of Sidewise and merge them into this official repo with attribution :)