LoginSignup
0
1

More than 5 years have passed since last update.

pacファイルからUser-Agentを参照することが出来なかったメモ

Last updated at Posted at 2016-06-21

IEとそれ以外のクライアントアプリで異なるProxyを使用するような設定をやりたくて,pacファイルでUser-Agentを判別することで可能かを調べたときのメモ。
結論としては,pacファイルで,User-Agentを参照する事は出来なかった。

試しに作成したpacファイル。このpacファイルでnavigator.userAgentが参照できるか確認した。

prooxy.pac
function FindProxyForURL(url, host) {
    alert("AAAA");
    alert(typeof navigator);
    alert(typeof navigator.userAgent);
    alert(navigator.userAgent);
    return "DIRECT";
}

上記でUser-Agentの文字列が取れたら,その文字列を元に返却するProxyを変更する予定だった。
IEの自動構成スクリプトに上記ファイルを設定して,IEを再起動してみたところ,

  1. "AAAA"のalertのボックス表示
  2. "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を参照する事は出来なかった。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1