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?
-
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 _Commented Dec 6, 2014 at 21:08
Add a comment
|
2 Answers
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
.)
-
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 Commented Dec 7, 2014 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 binCommented Dec 7, 2014 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...– shackraCommented Dec 8, 2014 at 20:37
-
1@IqbalAnsari: Unfortunately
eww
callsurl-http-user-agent-string
with the current buffer infundamental-mode
(a buffer returned byprocess-buffer
), so this does not work. I agree that it would be much better to set the user agent string foreww
only, but I don't know how to achieve this. Commented Dec 9, 2014 at 16:41 -
1@chenbin: You need to set
w3m-user-agent
. See this post by Sacha Chua for one way to do it. Commented Dec 9, 2014 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")