Can I run a bookmarklet/js on a mobile browser?
from fool@programming.dev to programming@programming.dev on 27 Oct 2024 16:57
https://programming.dev/post/21042209

A bookmarklet is a bookmark whose URL is JavaScript code instead of a site. It might be, for example,

javascript:document.querySelector('video').playbackRate = Number(prompt("speed")) || 1; void(0)

// formatted version:
javascript:
document
  .querySelector('video')
  .playbackRate = 
  Number(prompt("speed")) || 1; 
void(0)

so that if you click the bookmark, it sets the speed of the video to whatever you want (e.g. 3.7).

You could also run this directly in the URL bar (in some cases – I think desktop Chrome does that), or you can simply type alert() into the dev console (desktop Firefox prefers this for security reasons).

Is running my own arbitrary JS like this a thing on mobile? I’m on Android but I’m not sure if Brave disabled it – I vaguely remember it working once, but it doesn’t anymore. No luck on Firefox either. Maybe there’s a workaround?

#programming

threaded - newest

undefined@links.hackliberty.org on 27 Oct 2024 20:44 next collapse

I don’t have a great answer but I’m sure most modern browsers have locked down their address bar (and bookmarks) enough that it’s not possible without enabling developer features.

igorette@lemmy.ml on 27 Oct 2024 22:30 next collapse

On Firefox I use the tampermonkey extension to trigger javascript with a little overlay bar which is shown on the rendered website. I used an AI prompt to generate the userscript.

fool@programming.dev on 27 Oct 2024 22:45 collapse

I see, I forgot about tampermonkey. At that point I can also just paste a bookmarklet into the script space itself and enable when needed.

Firefox-based mobile browsers unload pages for me when I tab away (maybe it’s a Samsung killer thing? all outside of the scope of this question tho), which could be an issue, but if I’m careful then this method should do it. Thanks!

[deleted] on 28 Oct 2024 00:48 collapse

.