Difference between revisions of "WebKit UserAgent Override"

From WebOS Internals
Jump to navigation Jump to search
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 the other.

Revision as of 05:47, 26 August 2012

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 only uses a "token" feature, as described below.

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.

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. 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/.
  3. Then, create the following files, with the following content:
    • /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. Then, 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 the other.