I’ve been writing a bit lately about my growing use of EWW [1, 2, 3, 4]. I was always a little skeptical of those who said they made significant use of EWW for their browsing but then I realized that I had started doing the same thing. It certainly hasn’t replaced Safari but I am using it more and more.
It started fairly innocently. I use elfeed-webkit to render the web pages from my RSS feed. That has the significant disadvantage that my ad and tracking blocker doesn’t work for them. That, in turn, means that I get all sorts of junk displayed. It’s usually a dickover but sometimes there’s a seemingly never ending train of popup ads. Fortunately, elfeed (and elfeed-webkit) have a hot key to display the page in EWW and avoid all that. Now as soon as a dickover covers up the text or a avalanche of ads starting popping up, I simply switch over to EWW and read in peace. It’s surprising how little I need JavaScript.
As I said, I find myself using EWW more and more. It’s easy to call it from Embark when the point is on a URL and often I’ll just use it instead of invoking Safari. Of course, that brings up question. Can I switch from Safari to EWW when I need to? I couldn’t find any builtin way but I realized I already had everything I needed to do it. The first part is to retrieve the URL of the current Safari Web page. I’ve had a function to do this for a long time and use it all the time to capture links to the current Web page into Org. It’s pretty simple but restricted to macOS. Here it is.
(defun jcs-retrieve-url ()
"Retrieve the URL of the current Safari page as a string."
;; (org-trim (shell-command-to-string
;; "osascript -e 'tell application \"Safari\" to return URL of document 1'")))
(do-applescript "tell application \"Safari\" to return URL of document 1"))
The way to do this varies by browser and OS but is usually straightforward.
The second part is doing the actual switch. Again, it’s simple:
(defun jcs-switch-to-eww ()
"Invoke EWW for the current Safari web page"
(interactive)
(eww (jcs-retrieve-url)))
I put this in iCanHazShortcut and bound it to Ctrl+F7. It works fine except I haven’t yet figured out how to switch to Emacs from Safari so I have to press F6 for that. That’s a small price to play until I figure out the rest of the magic spell.
EWW, of course, has a way to switch to the default browser so it’s easy to pop back and forth as needed. It’s a small thing but makes my workflow easier.