I'm using eww lately for browsing the web looking for documentation and things like that. I dislike that eww receives the same web page as it were Firefox or Google Chrome, it cannot render web pages as those web browsers do. Then, what I want to achieve is to make eww tell the web sites that it visits that send the mobile friendly version of their web pages, thus, I would have a simpler layout rendered by eww (or at least that's my assumption).

  • 2
    Never used eww, but the trick could be to fake your User-Agent. Most of the time the webserver check that value before redirecting you to the mobile version of the website. – Nsukami _ Dec 6 '14 at 21:08

eww uses the url library, so we can add advice to url-http-user-agent-string to fake the User-Agent string:

(advice-add 'url-http-user-agent-string :around
            (lambda (ignored)
              "Pretend to be a mobile browser."
               "User-Agent: "
               "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30")))

I took a mobile browser User-Agent string from www.useragentstring.com.

With this advice I get the mobile version of google.com; your mileage may vary.

(I found this by using M-x apropos RET user-agent RET.)

  • 2
    You might want to check that current major mode is eww before changing the user-agent changing it unconditionally might break other packages depending on url library – Iqbal Ansari Dec 7 '14 at 10:44
  • what about emacs-w3m? how to get mobile version? As I know, these days we are actually use responsive design, so the point is fake screen size instead agent string. – chen bin Dec 7 '14 at 10:58
  • changing user-agent is something required because some web servers will serve a page lacking of Javascript, something which isn't evaluated by eww anyway... – shackra Dec 8 '14 at 20:37
  • 1
    @IqbalAnsari: Unfortunately eww calls url-http-user-agent-string with the current buffer in fundamental-mode (a buffer returned by process-buffer), so this does not work. I agree that it would be much better to set the user agent string for eww only, but I don't know how to achieve this. – Constantine Dec 9 '14 at 16:41
  • 1
    @chenbin: You need to set w3m-user-agent. See this post by Sacha Chua for one way to do it. – Constantine Dec 9 '14 at 16:43

In recent versions of Emacs, you can simply use the customization variable url-user-agent:

(setq url-user-agent "User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7\n")
  • Sorry, how recent? – shackra Jun 6 '15 at 18:30
  • It was introduced on Nov 5, 2014. – tmalsburg Jun 7 '15 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.