Last Resort backup solution?

Hi,

Is there any documentation you know of, explaining how one can save his work in tiddlywiki when the javascript scripts have been killed? Some kind of “Last resort” backup actions?

It just happened to me last week: after a few hours of work without saving my single-file tiddlywiki, I used the Advanced Search with a faulty regexp, and Firefox reacted with a notification along the lines of “a script on this page slows Firefox, [Stop] or [Wait] ?”.
Wait button had no effect, so I clicked on the Stop button, and I got doomed! :boom::dizzy_face:
UI elements on the page were dead, I could not save the wiki, and I’d loose everything if I’d reload the page. :sob:

I eventually found a way to backup my work, but it was quite involved:

  • used the Firefox console to explore the DOM
  • found some docs on the objects hierarchy of TW on internet, esp. $tw.wiki
  • didn’t find any simple way to trigger local file saving of the full TW
  • used $tw.wiki.allTitles() to explore the tiddler store
  • used $tw.wiki.getTiddlerText("$:/HistoryList") to list the last edited tiddlers
  • used $tw.wiki.getTiddlerAsJson(“xxxxxxx”) to export each useful tiddler to json
  • used Notepad++ to get rid of escape characters in Firefox’s json strings
  • put resulting json in a file
  • opened my last backup and imported json file
  • saved the result

I spare you the trial-and-error process, all in all it took me nearly one hour.

Well, I do know many ways to prevent getting myself in this situation in the very first place, but I think that if it happened to me, it could happen to someone else.

So maybe we can discuss the easiest solution, and then document it on tiddlywiki.com?

Fred

1 Like

Exactly what I was referring to here (talking to @Mohammad )

https://talk.tiddlywiki.org/t/advanced-search-in-fields-plugin-first-experimental-release/2000/7?u=codacoder

https://talk.tiddlywiki.org/t/advanced-search-in-fields-plugin-first-experimental-release/2000/11?u=codacoder

When (if) it happens again, use Firefox devtools to extract the contents of this script element to retrieve the JSON store:

You can edit that json too, if you understand JSON syntax.

1 Like

This doesn’t work, since the store is not updated prior to a save.

It certainly does. It worked for me recently, getting me out of a tight spot where reloading the wiki was breaking the wiki. All I did was edit the json, fix the problem, put the fixed json back, et voila – one working wiki.

That’s possible if the problem comes up at reloading. …

I did a test.

  • Create tiddler named: asdfasdfasdf
  • Open the DOM.
  • The tiddler isn’t part of the tiddler store. in the DOM

Right. My apologies, I should have been more clear…

I edited a JS macro, put it in a poorly constructed regex. Saved.

No problem, YET.

Reloaded to incorporate the new version of the JS macro.

Bang. :scream:

DevTools.

Copy out the store to an external editor.

Find the JS macro. Edit. Copy back to the store… in an external editor and save.

The rest you know.

You can try this:

  • F12 open the dev-console
  • In the Console tab enter the following text
  • $tw.saverHandler.saveWiki({template:"$:/core/save/all", downloadType: "text/plain", variables: {filename: "backup.html"}})
  • This should open the browser save file dialogue

If you didn’t mess up the $:/core/save/all template it should work. … I did test this with the TW halted at a breakpoint. … So the UI is frozen, similar to js-scripts stopped.


Edit: Improved command is: Last Resort backup solution? - #13 by pmario

3 Likes

I tried it on an already saved TW and this command produces a bit-perfect copy of the HTML file! :star_struck:

Thanks a lot @pmario!

Fred

1 Like

These instructions work with Firefox and Chromium (both latest version, tested on Linux).
They should also work with Chrome but I can’t test it.

Fred

Tiddly linked

3 Likes

A short note to be added, if you have installed Timimi, the below procedure:

  1. wont open the save dialogue
  2. wont use the backup.html
  3. will overwrite the buggy Tiddlywiki with recovered one!

Tested

Mario solution was tested on Chrome/Edge/FireFox latest version (2022.01.23) on Windows 10 and works successfully!

1 Like

The same behaviour is true if my “file-backups” addOn is installed. … I’ll try a second function that should always open the browser dialogue. New post will follow soon.

The command to always open the download dialogue is:

$tw.saverHandler.saveWiki({template:"$:/core/save/all", method: "download", downloadType: "text/plain", variables: {filename: "backup-x.html"}})

have fun!
mario

1 Like