openstyles/stylus

[Bug] All styles are gone

em-ex opened this issue ยท 25 comments

em-ex commented

Bug Report

Bug Description

After Firefox updated to v122.0, Stylus doesn't seem to work properly (buttons don't do anything) and years worth of custom styles are gone.

Screenshots

image

CSS Code

System Information

  • OS: Windows 10 64bit
  • Browser: Firefox 122
  • Stylus Version: 1.5.45

Additional Context

Is there a chance I can recover my custom styles? Where are they located?

tophf commented

Sounds like a bug in Firefox. Try the methods in our FAQ or find another tutorial. Also make sure you backup your data daily, I've also learned this painful lesson many years ago.

em-ex commented

Excuse me, but how is this a Firefox bug if Stylus is the only extension that stopped working?

tophf commented

Bugs are irregularities that occur due to a specific combination of factors. It is also possible that the bug affects a random extension. Until the actual reason of the bug is investigated in the source code there's no way to tell.

tophf commented

What I know for sure is that Stylus can't remove or lose its styles due to its own code. Please try the methods in our FAQ, there's a possibility the styles are still there.

tophf commented

You also mentioned that buttons don't work, which implies that Firefox couldn't load some of the extension's scripts. The possible reason is a corruption of the installed xpi (you can try reinstalling it but make sure to copy the entire profile first to preserve the data). There's also a known bug in Firefox when the profile directory contains NTFS junctions and/or links to RAM drive like ImDisk.

em-ex commented

I did reinstall the extension and it seems to work now - thanks for the suggestion.
Now providing I can't just replace the DB, any tips on how to migrate my styles from old DB to new DB?

tophf commented

I think you can just copy the files from the old folder into the new one and it might work even if the internal id has changed.
See https://github.com/openstyles/stylus/wiki/FAQ#where-are-my-styles-stored

em-ex commented

The extension breaks and the UI stops responding as soon as I replace the new DB with the old and restart the browser.
In the debug console I get the same error as it was giving prior to reinstalling the extension:

TypeError: data.sections is undefined
style-manager.js:560:27

image

tophf commented

It means the database is either entirely broken or there's a broken style. Try viewing it in devtools -> Storage -> IndexedDB -> stylish -> styles.

em-ex commented

No luck with replaced DB: the Storage tab is just empty.
However, I see my custom rules in the old DB if I use third party tools to browse SQLite. But I don't know the format of the data blob even if I was brave enough to manually migrate over a hundred rules :)

tophf commented

Try following #1094.

em-ex commented

Unfortunately moz-idb-edit errors with TypeError: KeyCodec._decode_number() missing 1 required positional argument: 'type' on my weirdly broken DB.

Edit: I tried running it on a DB from a year old disk backup, when the extension worked fine - same error. Trying to use the tool on the default empty DB results in empty JSON, so I guess the tool works

This required some focused time for debugging, which wasn't easy to carve out, but I did it. I'll leave this here in case someone gets stuck in the same situation.

moz-idb-edit just got updated - it's a module now and it switched from python-snappy to cramjam for de/compression. But it still didn't work for me out of the box.
I patched it to run in my environment:

  • imported sys in moz-idb-edit so that sys.exit(mozidbedit.main()) wasn't erroring
  • changed mozidbedit\mozidb.py line 126 from return cls._decode_number(buf, index, KeyType.FLOAT) to return cls._decode_number(cls, buf=buf, index=index, type=KeyType.FLOAT) to fix that missing 1 required positional argument error in KeyCodec._decode_number()

Now running the tool yielded my entire database in JSON, sort of. It wasn't the JSON that Stylish would accept, so I put together a quick PowerShell script which takes the output of monkey-patched moz-idb-edit tool and turns it into JSON suitable for Stylish importer:

$json = gc ~\desktop\489858440shtsyil.json
# clean up results of moz-idb-edit export
$clean = $json | % {
    # - remove internal ID for each style item
    # - replace head object with array tag
    $_ -replace "^ \d+.\d+: \{", "    {" `
       -replace "^{\d+.\d+: \{", "[`n{"
}
# - replace tail object with closing array tag
$clean[-1] = $clean[-1] -replace "\}\}\n?$", "}`n]`n"

# save as UTF8 without BOM since i'm using old version PS
Set-Content ([Text.UTF8Encoding]::new().GetBytes((
    $clean -join "`n"
))) -Encoding Byte -PSPath ~\desktop\4import.json

Resulting JSON brought back 100 out of my 102 custom rules into Stylish. The remaining two have been corrupted for a while and they weren't active anyway.

I'm having what seems to be a similar problem, all styles disappeared from UI and management screen, clicking the add-on's UI does nothing, but... installed styles, though not listed by Stylus, still apply to pages!

In my case reinstalling Stylus did nothing. I am afraid to uninstall -> reinstall add-on because of my data (several dozen styles from over the years). However based on above I suspect the DB is corrupted. But I am not as sophisticated as the original poster here (who seems to be compiling custom builds of software) as far as solving it.

So does the DB just corrupt sometimes? Could it be something like an SSD going bad?

If you're comfortable with it, link me to your DB so I can try to extract the styles

If the styles are applied, then they're not gone and the db is fine. Sounds like a bug in the browser or in the extension. Click the export button in the style manager and inspect the file that it downloads.

If you're comfortable with it, link me to your DB so I can try to extract the styles

Thanks for your offer. Since export doesn't function, is there an already-existent discrete DB file that I can share?

Is it perhaps
profile01.default\storage\default\moz-extension+++23fb144e-4e28-48b4-84fd-87d808e12515\idb\159652269dsrtaf.sqlite

If the styles are applied, then they're not gone and the db is fine. Sounds like a bug in the browser or in the extension. Click the export button in the style manager and inspect the file that it downloads.

Unfortunately, the "no buttons work" applies to the add-on's options screen as well. I can only access Stylus' options screen from the Firefox (Windows 10 x64, latest FF version) add-on manager:
Clip 009333 FF 5190  Add-ons Manager โ€” Mozilla Firefox

And it looks completely empty:
Clip 009334 FF 5191  Stylus โ€” Mozilla Firefox
The export and import buttons do nothing when clicked.

If all buttons don't work then it's definitely a bug in the browser. I know Firefox can't handle ImDisk RAM drives, maybe other nonstandard types like network shares are also affected.

See if there are errors in devtools console.

idb\489858440shtsyil.sqlite is where I extracted all my styles from

See if there are errors in devtools console.

A couple red errors but nothing immediately jumps out (meaning seems to reference being caused by Stylus).

Noticed something surprising. I maintain several separate Firefox instances and I have the exact same Stylus symptoms on a secondary FF instance I rarely open. That suggests the problem isn't SSD corruption of a file. (Also, I don't use a RAM disk.)

I tried falling back to a couple older Stylus versions but the management screen is still empty and Stylus UI buttons non-functioning.

idb\489858440shtsyil.sqlite is where I extracted all my styles from

๐Ÿ™ zip pw is my username.

489858440shtsyil.zip

Edit: Above upload is 404ing for me. Here's Dropbox.

Any error in devtools console for the style manager page is directly related to Stylus.

Any error in devtools console for the style manager page is directly related to Stylus.

Ah, I had misunderstood the context of the tool. OK, yes, manager page does show this exception:
Clip 009335 Developer Tools โ€” Stylus โ€” moz-extension___23fb144e-4e28-48b4-84fd-87d808e12515_

The error says you have a broken style. I'll fix Stylus to warn about such styles. Meanwhile you can find them by pasting and running the following code in devtools console prompt: await API.styles.getAll().then(all=>all.filter(s=>!s||!s.sections))

I can't seem to be able to extract anything even with the patch from #1094 - the reading loops returns same byte sequence b'\x10\xbf\xf0' over and over and nothing else gets outputted