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).
How can I ask for a web server to serve their "mobile friendly" version of their web pages with eww?
Asked
Active
Viewed 726 times
11
-
2Never 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 06 '14 at 21:08
2 Answers
11
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."
(concat
"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
.)

Constantine
- 9,072
- 1
- 34
- 49
-
2You 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 07 '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 07 '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 08 '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 09 '14 at 16:41
-
1@chenbin: You need to set `w3m-user-agent`. See [this post by Sacha Chua](http://sachachua.com/blog/2008/08/emacs-and-w3m-fake-your-user-agent/) for one way to do it. – Constantine Dec 09 '14 at 16:43
-
this doesn't appear to work in latest emacs, it prevents pages from ever loading – Joseph Garvin Feb 05 '15 at 23:24
-
figured it out, at the end of the user agent string you need to add "\r\n" – Joseph Garvin Feb 05 '15 at 23:38
0
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")

tmalsburg
- 2,540
- 1
- 14
- 29