2023-07-11
How I move URLs between browsers in my Unix desktop environment
When I wrote about how blocking JavaScript by default is not an easy path, I mentioned this:
I also have a bunch of magic things in my personal desktop environment that make it relatively easy to start with a link or URL from one browser [the one with JavaScript off] and open it in the other [the one with JavaScript on].
Recently poebbel (in a comment) asked how this works. While I've mentioned the various pieces in various articles, I've never put the picture together in one place.
For my desktop environment, I use fvwm
with a completely custom setup (this old entry on my desktop is
still pretty accurate MyDesktop). These days my multiple browsers are actually
Firefox profiles, so I have a cover script to run Firefox with my
'JavaScript enabled' profile and whatever remaining command line
options; this is more or less 'firefox -P Javascript "$@"
'
(although in practice I always use it with --new-window, because
for browser organization I usually prefer windows over tabs).
I have two ways to push URLs into my JavaScript enabled browser (profile). First, I can use dmenu to run the 'jfox' cover script, passing the URL on the command line (running selected programs is one of the things my dmenu environment will do). Dmenu itself has a key binding to paste in the current selection (Ctrl-Y for me), so the usual sequence is to tap my key for bringing up dmenu, type 'jf<tab>' to complete it, space, Ctrl-Y to paste the selected URL, and then Return to run it. Second, one of my fvwm mouse button bindings brings up a menu of 'things to do with the current selection'. One of these things is another script that gets the current X selection (which you can do with, for example, xsel (also)) and runs 'jfox <URL-selection>'.
(The selection handling script is actually a bit more sophisticated; it will open a brand new JavaScript-enabled blank window if the X selection doesn't look like a plausible URL.)
To get the URL I want as the X selection, there are two options depending on where the URL is. If what I want to (re)open in my JavaScript Firefox is the current page I'm viewing (for example, because it turns out to only work with JavaScript enabled), I'll triple-click Firefox's URL bar to select it. If it's a link on the current page, I'll use Firefox's context menu and 'Copy Link'. Then I'll usually use one or the other process to get a new JavaScript Firefox window with the URL. If for some reason I want the URL as a tab in an existing JavaScript Firefox window, I'll Ctrl-T to make a new blank tab and then paste the URL into the URL bar.
All of this is not completely fluid and lightning fast. I could speed up some of it by creating a fvwm keyboard binding that ran my 'get X selection and run JavaScript Firefox with it' cover script, but I'd still have to select the URL one way or another in my normal Firefox, and there's probably no good way to speed that up. In practice this dance is fast enough for the times when I need it, and I try not to need it a lot.
(My default reaction when a web page demands JavaScript is to close the tab or window, unless I decide I really want to read it.)
You could probably build something like this in any environment that lets you get the current selection and run a script in response to a special key press. Firefox profiles (and second browsers) work in all desktop environments, and every browser will take URLs on the command line. A pop-up command line dmenu-like thing and especially a custom mouse button menu are more specific to Unix and fvwm (or similar window managers), but I believe that there are dmenu-like things for Wayland that work in at least some of the Wayland window manager or desktop environments.