lobste.rs has a js-error: here is a mitigation

5 points by refp 11 hours ago on lobsters | 16 comments

[OP] refp | 10 hours ago

The previous tampermonkey script is sadly unstable, use the below:

.

  1. Install ViolentMonkey or TamperMonkey
  2. Create a new script (see next section)
  3. Reload the page.

.

Note: tampermonkey requires "enable user scripts" in your browser's extension settings, ViolentMonkey has no such requirement.


This works consistently for me now.

// ==UserScript==
// @name         lobste.rs qS/qSA repair
// @match        https://lobste.rs/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

let nonce = null;
for (const s of document.scripts) if (s.nonce) { nonce = s.nonce; break; }
if (!nonce) throw new Error('no nonce found');

const el = document.createElement('script');
el.nonce = nonce;
el.type = 'module';
el.textContent = `
window.qS = (a, b) => b === undefined ? document.querySelector(a) : a.querySelector(b);
window.qSA = (a, b) => b === undefined ? [...document.querySelectorAll(a)] : [...a.querySelectorAll(b)];

const map = JSON.parse(document.querySelector('script[type="importmap"]').textContent);
const mod = await import(map.imports.user + '?retry=' + Date.now());
window._LobstersFunction = mod._LobstersFunction;
document.dispatchEvent(new Event('DOMContentLoaded'));
`;
document.documentElement.appendChild(el);
el.remove();

[OP] refp | 10 hours ago

@lalitm see above, this should work (TM)

lalitm | 10 hours ago

It works! Thanks so much!

[OP] refp | 10 hours ago

please upvote the relevant comment so that it drifts to the top, I cannot edit the original posting anymore.

lalitm | 10 hours ago

Done!

pushcx | 10 hours ago

Sorry about this, I'm working on it now. More technical details here.

[OP] refp | 10 hours ago

Thanks @pushcx! 💪

[OP] refp | 11 hours ago

⚠️ ⚠️ ⚠️ ⚠️

The originally posted snippet is faulty, please see this:

⚠️ ⚠️ ⚠️ ⚠️


Notes
  • as a community there are probably easier mitigations we could come up with together, but the TamperMonkey approach works fine.
  • make sure you enable "Allow User scripts" under the extension settings if you like me installed it only for this).

gerikson | 11 hours ago

I assume this has been reported to the public repo?

[OP] refp | 11 hours ago

There is the following issue:

There has been heavy activity regarding this in ´#lobsters` (IRC), so at least it is known/discussed there.

[OP] refp | 11 hours ago

Do you mind trying the approach and perhaps upvote this story as a sign of success?


I hope it is as easy for others to fix as it was for me, but with that I don't really know what is considered "easy" given that I assume most do not have web dev experience.

lalitm | 11 hours ago

I just tried the TamperMonkey approach and sadly does not seem to have done anything: I'm still seeing the error in console and upvoting doesn't work either.

[OP] refp | 10 hours ago

Ok, so there is a race between the tamperscript being invoked vs the lobster's javascritp is executing. If you have the dev-console open the load slows down enough to always inject our script, so.. browsing with dev-tools open seems to make it more stable!

lalitm | 10 hours ago

On a M4 Macbook Air, sadly even having Devtools doesn't seem to slow things down enough!

[OP] refp | 11 hours ago

  • someone just upvoted this story so it seems to work for someone else but me.
  • Did you enable "Allow user scripts" in the extension, as well as reloading the page?

I have never written anything for tampermonkey before so there might something which isn't ideal in the proposed snippet, but it seems to be working for me.

Edit: Seems to go back to b0rked on some page transitions, working on a fix!

srtcd424 | 11 hours ago

wfm using violentmonkey on vivaldi, if that helps.