browser-dependency.md (9807B)
1 Title: Trying to avoid browser dependency. 2 Author: paco 3 Date: 2019-05-07 4 Type: article 5 6 Web browsers are almost the only GUI programs I use. They are also the most 7 bloated and vulnerable programs one can have installed on desktop/laptop. 8 9 Those browsers have to handle a lot of external code that comes from the 10 websites visited. Not only static html (which is already problematic in some 11 cases) but also JavaScript, which has to be interpreted and run in your machine 12 with the obvious risk. 13 14 Is not only a matter of security, but also privacy. Almost every website out 15 there is tracking you in some way or another. Or worst, is using one of the big 16 companies to track you, which makes their profiling even easier ... 17 18 And then there's the _ups!_ moments like the recent [Firefox bug][1] that 19 deactivated all the user plugins. The worst part in my opinion is trying to fix 20 the thing using the _"Studies system"_, which already has a reputation ... 21 22 The other big browser, Chrome is not free of all this stuff. They spy on you 23 directly without even hiding it. 24 25 Here you can find a series of techniques to use web browsers as little as 26 possible. 27 28 ## Basic browsing 29 30 For basic stuff, like sites that are mostly text as Wikipedia or others, one 31 can use a text based browser like [lynx][2]. This becomes impossible with sites 32 that make heavy use of JavaScript or sites that require captcha to login ... In 33 that case, the only alternative I can think of is use a conventional browser 34 with plugins like uBlock Origin or Privacy Badger. 35 36 ## Bookmarks 37 38 There are some ways of have your bookmarks totally independent from a browser. 39 I choose to use [shiori][3]. It's a terminal utility that you can use to add, 40 search, or open bookmarks. It also has a web interface if you prefer that. 41 42 A simple search can be done like this: 43 44 shiori search keyword 45 46 You cal also specify tags in the search with `-t`. Then you can open it in your 47 default browser with: 48 49 shiori open id 50 51 Take a look at `help`, it's really easy. 52 53 You can also import/export bookmarks in html format as most browsers 54 understand, so migrating to/from `shiori` is quite easy. 55 56 ## Downloads 57 58 Whenever I can, I use [curl][4], `ftp(1)` or [wget][5] from the command line with 59 direct links. If using a text based browser, then it should have its own way of 60 dealing with downloads. 61 62 Some sites do not like user that do not use conventional browsers, as those are 63 more difficult to track (not impossible, just a bit more difficult). Some of 64 them block requests that don't come from _"regular"_ user agents, so it's 65 usually a good idea to configure your tools to identify themselves as Mozilla 66 Firefox or Google Chrome. Most of the times that is enough. 67 68 If using bittorrent to download stuff, the problem is to find a torrent website 69 that is not completely full of crap and you can just take the magnet links 70 (because you should be using magnet links). Try to use API calls if your 71 favourite tracker allows it. 72 73 I usually use [rarbg][6]. You have a lot of alternatives to interact with its 74 [api][7]. A long time ago I did some Perl module for it called 75 [Rarbg::torrentapi][8]. Then I use a sort of interactive script to search 76 torrents on the terminal, it pairs with [transmission][9] to send the magnet 77 links directly to the torrent client. 78 79 #!/usr/bin/env perl 80 81 use v5.24; 82 use strict; 83 use warnings; 84 use Rarbg::torrentapi; 85 use Getopt::Long; 86 no warnings 'experimental'; 87 88 sub usage { 89 say 90 "Usage: $0 [--list] [--search <string>] [--categories <category>] [--limit <n>]"; 91 say "\t--list\t\t\tlists last added torrents sorted by seeds."; 92 say 93 "\t--search <string>\tsearches for <string> and returns sorted by seeds"; 94 say 95 "\t--category [movies|tv|music|xxxx]\tuses those categories (defaults to movies)"; 96 say "\t--limit [25|50|100]\tShows 'n' results (defaults to 25)"; 97 exit 1; 98 } 99 100 my $tapi = Rarbg::torrentapi->new(); 101 my $counter = 0; 102 my $search = ""; 103 my $list; 104 my $result; 105 my $raw_category = ''; 106 my $category; 107 my $limit = 25; 108 109 GetOptions( 110 "search=s" => \$search, 111 "list" => \$list, 112 "category=s" => \$raw_category, 113 "limit=i" => \$limit 114 ) or usage(); 115 116 given ($raw_category) { 117 when ( $_ eq 'movies' or $_ eq 'tv' ) { 118 $category = $raw_category; 119 } 120 when ( $_ eq 'music' ) { 121 $category = '2;23;24;25;26'; 122 } 123 default { 124 $category = 'movies' 125 } 126 } 127 128 if ($search) { 129 $result = $tapi->search( 130 { sort => 'seeders', 131 limit => $limit, 132 category => $category, 133 search_string => $search 134 } 135 ); 136 } 137 elsif ($list) { 138 $result = $tapi->list( 139 { sort => 'seeders', 140 limit => $limit, 141 category => $category 142 } 143 ); 144 } 145 else { 146 usage(); 147 } 148 149 if ( ref($result) eq 'ARRAY' ) { 150 foreach my $t ( @{$result} ) { 151 printf( 152 "%d -> %s (%.2f GB # %d seeds)\n", 153 $counter, $t->title, $t->size / 1073741824, 154 $t->seeders 155 ); 156 $counter++; 157 } 158 } 159 elsif ( ref($result) eq 'Rarbg::torrentapi::Error' ) { 160 die "[*] We got an error: $result->{error}"; 161 } 162 else { 163 die "[*] Unexpected Error"; 164 } 165 166 print "Input selection, separated by spaces. (Ctrl+C to quit) "; 167 my $selection = <STDIN>; 168 chomp $selection; 169 170 if ( $selection =~ m/\d{1,2} ?/ ) { 171 my @selections = split( / /, $selection ); 172 foreach my $s (@selections) { 173 say "[*] You selected: " . $result->[$s]->title; 174 say " [-] sending magnet to transmission:\n" 175 . $result->[$s]->download; 176 my $magnet = $result->[$s]->download; 177 `transmission-remote MYTORRENTHOST --authenv -a $magnet`; 178 } 179 } 180 else { 181 die "selection is not a number!"; 182 } 183 184 ## RSS feeds 185 186 The best solution I found for this is [newsboat][10]. You can use it directly 187 (providing a list of feeds to pull from) or connecting it to a supported 188 external service like [ttrss][11]. I happen to have access to a `ttrss` 189 installation, so I use that and also have the Android app on my phone. That way 190 I keep track of what I have read/seen. 191 192 `newsboat` allows you to configure the browser it will use to open links. I 193 find useful to have a wrapper script as configured browser, so it routes the 194 different kinds of links to different programs, and defaults to a web browser 195 if needed. I also use it for other stuff on the command line, is pretty 196 convenient. 197 198 #!/usr/bin/env bash 199 200 ext="${1##*.}" 201 videoSites="youtube.com|youtu.be|diode.zone|peertube.social" 202 videoFiles="mkv mp4 gif webm mpd" 203 audioFiles="mp3 flac" 204 imageFiles="png jpg jpeg" 205 206 if echo "$imageFiles" | grep -q -w "$ext"; then 207 feh -q "$1" & disown 208 elif echo "$videoFiles" | grep -q -w "$ext"; then 209 mpv --really-quiet --pause --keep-open "$1" & disown 210 elif echo "$audioFiles" | grep -q -w "$ext"; then 211 # I like podcasts and the like to open on a small terminal 212 urxvtc -geometry 60x6 -e mpv --pause --keep-open "$1" & disown 213 elif echo "$@" | grep -q -E "$videoSites"; then 214 mpv --really-quiet --pause "$1" & disown 215 else 216 firefox --private-window "$1" > /dev/null 2>&1 & disown 217 fi 218 219 And then you tell `newsboat` to use it like so: 220 221 browser "/path/to/my/script/linkhandler.sh %u" 222 223 ## Images 224 225 You can use [feh][12] to see links to images. It just works. 226 227 It can also be used to set up your background image on simple window managers, 228 invoked from `.xinitrc` or `.xsession` 229 230 ## Videos (and streaming) 231 232 A good alternative to watch videos and streaming on the browser is [mpv][13]. It 233 has integration with [youtube-dl][14] (which not only "understands" youtube 234 links, but many many more). With a bit of configuration you won't need the 235 browser for video any more. Here is my `~/.config/mpv/mpv.conf` 236 237 # sound works better like this on OpenBSD 238 ao=sndio 239 # try gpu accelerated video 240 vo=gpu,xv 241 # full screen by default 242 fs=yes 243 # user agent ... because the web sucks. 244 user-agent="Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0" 245 # moarrr cache 246 cache=yes 247 cache-default=8192 248 # no 4k monitor so limit to best 1080 249 ytdl-format=bestvideo[height <= 1080]+bestaudio/best 250 # do not send that through the HE tunnel (ignore if you do not have this) 251 ytdl-raw-options=force-ipv4= 252 253 Keep in mind that some streams might not work with mpv under OpenBSD (my OS of 254 choice). That's because `ffmpeg` does not come with DASH demuxing compiled in 255 by default. I sent a patch to the port maintainer some time ago. I hope it will 256 be commited soon. In the mean time contact me if you need that functionality 257 and I'll send you the patch and instructions. 258 259 ## Conclusion 260 261 So those are the programs I use to try to stay away from the browser as much as 262 possible. If you have other alternatives or suggestions, contact me and I'll 263 add them here. 264 265 [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1548973 266 [2]: https://lynx.invisible-island.net/ 267 [3]: https://github.com/RadhiFadlillah/shiori 268 [4]: https://curl.haxx.se/ 269 [5]: https://www.gnu.org/software/wget/ 270 [6]: https://rarbg.com/ 271 [7]: https://torrentapi.org/ 272 [8]: https://metacpan.org/pod/Rarbg::torrentapi 273 [9]: https://transmissionbt.com/ 274 [10]: https://newsboat.org/ 275 [11]: https://tt-rss.org/ 276 [12]: https://feh.finalrewind.org/ 277 [13]: https://mpv.io/ 278 [14]: https://youtube-dl.org/