Difference between revisions of "WebKit UserAgent Override"

From WebOS Internals
Jump to navigation Jump to search
(misc cleanup, added some clarification)
 
(2 intermediate revisions by one other user not shown)
Line 10: Line 10:
 
Under the "[General]"  section, you will need to add the "UserAgentOverride" key. An example is below:
 
Under the "[General]"  section, you will need to add the "UserAgentOverride" key. An example is below:
  
<pre><nowiki>
+
<pre>
 
[General]
 
[General]
 
...
 
...
 
UserAgentOverride=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1
 
UserAgentOverride=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1
 
...
 
...
</nowiki></pre>
+
</pre>
  
 
== Ok, great, but this overrides LunaSysMgr, right? ==
 
== Ok, great, but this overrides LunaSysMgr, right? ==
Line 22: Line 22:
 
= webOS 2.2.4 and earlier =
 
= webOS 2.2.4 and earlier =
 
== What It Is and What It Does ==
 
== What It Is and What It Does ==
Earlier versions of webOS do not have a wholesale override feature. It only uses a "token" feature, as described below.
+
Earlier versions of webOS do '''not''' have a wholesale override feature. It does, however, have a "tokens" feature, which can '''add''' to your user-agent.
  
The WebKit implementation reads the contents of each file in the tokens directory, strips the spaces from it, and then appends this to the user-agent string after a semi-colon. I will describe below how to add these tokens. Some websites may only read "iphone" or "iOS" from the user-agent and think that you have an iPhone.
+
The WebKit implementation reads the contents of each file in the tokens directory, strips the spaces from it, and then appends this to the user-agent string after a semi-colon. Some websites may only read "iphone" or "iOS" from the user-agent and think that you have an iPhone.
  
 
== How to add tokens to the User-Agent ==
 
== How to add tokens to the User-Agent ==
 
# Create a directory somewhere. Either in /etc/palm/ or somewhere in /media/internal/. I created /etc/palm/uatokens/ so that I can create different subdirectories for different types of user agents.
 
# Create a directory somewhere. Either in /etc/palm/ or somewhere in /media/internal/. I created /etc/palm/uatokens/ so that I can create different subdirectories for different types of user agents.
# Then create a subdirectory for the user-agent you want to try to mimic. For this example, create iphone. You should have /etc/palm/uatokens/iphone/.
+
# Create a subdirectory for the user-agent you want to try to mimic. For example, create iphone. You should have /etc/palm/uatokens/iphone/.
# Then, create the following files, with the following content:
+
# For each "token" you want to add, create a file.  For example, to have "<tt>iPhone; Safari/7534.48.3; AppleWebKit/534.46; Version/5.1; Mobile/9A334; CPUiPhoneOS5_0likeMacOSX</tt>" in your user-agent, create the following:
#* /etc/palm/uatokens/iphone/cpu:<pre><nowiki>CPU iPhone OS 5_0 like Mac OS X</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/cpu:<pre>CPU iPhone OS 5_0 like Mac OS X</pre>
#* /etc/palm/uatokens/iphone/iphone:<pre><nowiki>iPhone</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/iphone:<pre>iPhone</pre>
#* /etc/palm/uatokens/iphone/mobile:<pre><nowiki>Mobile/9A334</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/mobile:<pre>Mobile/9A334</pre>
#* /etc/palm/uatokens/iphone/safari:<pre><nowiki>Safari/7534.48.3</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/safari:<pre>Safari/7534.48.3</pre>
#* /etc/palm/uatokens/iphone/version:<pre><nowiki>Version/5.1</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/version:<pre>Version/5.1</pre>
#* /etc/palm/uatokens/iphone/webkit:<pre><nowiki>AppleWebKit/534.46</nowiki></pre>
+
#* /etc/palm/uatokens/iphone/webkit:<pre>AppleWebKit/534.46</pre>
# Then, edit /etc/palm/browser-app.conf as below (the trailing '/' on the path is MANDATORY):
+
# Edit /etc/palm/browser-app.conf as below (the trailing '/' on the path is MANDATORY):
  
<pre><nowiki>[General]
+
<pre>[General]
 
...
 
...
 
UserAgentTokensPath=/etc/palm/uatokens/iphone/
 
UserAgentTokensPath=/etc/palm/uatokens/iphone/
 
...
 
...
</nowiki></pre>
+
</pre>
  
  
Line 50: Line 50:
 
== Ok, great, but this overrides LunaSysMgr, right? ==
 
== Ok, great, but this overrides LunaSysMgr, right? ==
 
Nope! LunaSysMgr uses a separate instance of WebKit with different preferences.
 
Nope! LunaSysMgr uses a separate instance of WebKit with different preferences.
 +
 +
= Platform Independent Notes =
 +
LunaSysMgr loads an instance of WebKit, and then reads WebKit settings from /etc/palm/browser.conf. BrowserServer loads another instance of WebKit, and then reads WebKit settings from /etc/palm/browser-app.conf. This is why you can change the User-Agent in one, and not affect the other.

Latest revision as of 02:40, 21 July 2013

webOS 3.0.0 and greater

What It Is and What It Does

The user-agent override is a feature that allows one to do a wholesale replacement of the user-agent.

How to Override the User-Agent

The BrowserServer loads an instance of WebKit that uses the /etc/palm/browser-app.conf configuration file.

To change the User-Agent, you need to edit this (/etc/palm/browser-app.conf) file, with the proper token.

Under the "[General]" section, you will need to add the "UserAgentOverride" key. An example is below:

[General]
...
UserAgentOverride=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1
...

Ok, great, but this overrides LunaSysMgr, right?

Nope! LunaSysMgr uses a separate instance of WebKit with different preferences.

webOS 2.2.4 and earlier

What It Is and What It Does

Earlier versions of webOS do not have a wholesale override feature. It does, however, have a "tokens" feature, which can add to your user-agent.

The WebKit implementation reads the contents of each file in the tokens directory, strips the spaces from it, and then appends this to the user-agent string after a semi-colon. Some websites may only read "iphone" or "iOS" from the user-agent and think that you have an iPhone.

How to add tokens to the User-Agent

  1. Create a directory somewhere. Either in /etc/palm/ or somewhere in /media/internal/. I created /etc/palm/uatokens/ so that I can create different subdirectories for different types of user agents.
  2. Create a subdirectory for the user-agent you want to try to mimic. For example, create iphone. You should have /etc/palm/uatokens/iphone/.
  3. For each "token" you want to add, create a file. For example, to have "iPhone; Safari/7534.48.3; AppleWebKit/534.46; Version/5.1; Mobile/9A334; CPUiPhoneOS5_0likeMacOSX" in your user-agent, create the following:
    • /etc/palm/uatokens/iphone/cpu:
      CPU iPhone OS 5_0 like Mac OS X
    • /etc/palm/uatokens/iphone/iphone:
      iPhone
    • /etc/palm/uatokens/iphone/mobile:
      Mobile/9A334
    • /etc/palm/uatokens/iphone/safari:
      Safari/7534.48.3
    • /etc/palm/uatokens/iphone/version:
      Version/5.1
    • /etc/palm/uatokens/iphone/webkit:
      AppleWebKit/534.46
  4. Edit /etc/palm/browser-app.conf as below (the trailing '/' on the path is MANDATORY):
[General]
...
UserAgentTokensPath=/etc/palm/uatokens/iphone/
...


Your User-Agent will now look like this (Pre3, with tokens to make it look like an iPhone running iOS 5.1):

Mozilla/5.0 (Linux; webOS/2.2.4; U; en-US) AppleWebKit/534.6 (KHTML like Gecko) webOSBrowser/221.56 Safari/534.6 Pre/3.0; iPhone; Safari/7534.48.3; AppleWebKit/534.46; Version/5.1; Mobile/9A334; CPUiPhoneOS5_0likeMacOSX

Ok, great, but this overrides LunaSysMgr, right?

Nope! LunaSysMgr uses a separate instance of WebKit with different preferences.

Platform Independent Notes

LunaSysMgr loads an instance of WebKit, and then reads WebKit settings from /etc/palm/browser.conf. BrowserServer loads another instance of WebKit, and then reads WebKit settings from /etc/palm/browser-app.conf. This is why you can change the User-Agent in one, and not affect the other.