IEとそれ以外のクライアントアプリで異なるProxyを使用するような設定をやりたくて,pacファイルでUser-Agentを判別することで可能かを調べたときのメモ。
結論としては,pacファイルで,User-Agentを参照する事は出来なかった。
試しに作成したpacファイル。このpacファイルでnavigator.userAgentが参照できるか確認した。
function FindProxyForURL(url, host) {
alert("AAAA");
alert(typeof navigator);
alert(typeof navigator.userAgent);
alert(navigator.userAgent);
return "DIRECT";
}
上記でUser-Agentの文字列が取れたら,その文字列を元に返却するProxyを変更する予定だった。
IEの自動構成スクリプトに上記ファイルを設定して,IEを再起動してみたところ,
- "AAAA"のalertのボックス表示
- "undefined"のalertのボックス表示
までで終わった。User-Agent文字列は取得出来なかった。
google先生に聞いてみたところ
http://findproxyforurl.com/pac-functions/
に以下の記載があるのを見つけた。
Each browser implements PAC in a sandbox, allowing access to only those JavaScript
functions required to operate and nothing more. As an example,
it isn’t possible to access the browser user agent string in a PAC file, a string available to a normal web page.
という事で,pacファイルからUser-Agentを参照する事は出来なかった。