linuxbrowseruser-agentagentw3m

How to set user agent in w3m


I'm using w3m. How do I go about overriding the user agent of this text based web browser? I have tried setting -header "User-Agent: blah" as an example, but I get the following error:

w3m: Can't load blah.

Solution

  • I set the User-Agent by modifying the file ~/.w3m/config and modifying the user_agent line. I have the following text and it seems to work as expected: user_agent Mozilla/5.0 (Linux i686; U; w3m 0.5.3; en). That has no : or = signs in it, just so you get an idea of the syntax used.

    This is with w3m version 0.5.3.

    You can also set it with w3m -header 'User-Agent: blah' but the problem there is that it appears twice in the request. You can see the headers that w3m uses if you set up a netcat "webserver":

    $ netcat -lp 9999
    # then in another terminal:
    $ w3m -header 'User-Agent: foo' http://localhost:9999
    # back at netcat:
    GET / HTTP/1.0
    User-Agent: w3m/0.5.3
    Accept: text/html, text/*;q=0.5, image/*
    Accept-Encoding: gzip, compress, bzip, bzip2, deflate
    Accept-Language: en;q=1.0
    Host: localhost:9999
    User-Agent: foo
    

    So it sends 2 User-Agent strings, which may not be parsed correctly by the real HTTP server.