Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

proxy

拡張されたProxy Auto-Configuration (PAC) file (これはウェブのリクエストをプロキシー化するポリシーを実装します) を実装するのにプロキシー API を使います。この実装は標準の PAC 設計といくつかそれていて、なぜなら PAC ファイルのデファクト仕様は 1995 年頃の初期実装から変えられてないためです。仕様を維持している標準化団体はありません。

Google Chrome では同じく"proxy"という拡張機能 API が提供されていて、その機能はこの API と似ていて、拡張機能はプロキシーポリシーを使うことができます。しかし、Chrome API の設計はこの API とまったく違います。Chrome の API では拡張機能は PAC ファイルを定義できて、明示的なプロキシールールも定義できます。このため拡張機能 PAC ファイルも使用できて、この API は PAC ファイルアプローチのみをサポートします。この API は Chromeproxy API と互換性がないため、この API はbrowser 名前空間のみで利用できます。

この API を使うには、"proxy"パーミッションが必要です。

PAC ファイルと通信する

PAC ファイルと拡張機能のバックグラウンドページ(やその他の権限つきページ、ポップアップページのようなもの)とでメッセージを交換できて、その手段はruntime.sendMessage()runtime.onMessage

PAC ファイルにメッセージを送るには、toProxyScript オプションをセットしなければなりません:

js
// background.js// Log any messages from the proxy.browser.runtime.onMessage.addListener((message, sender) => {  if (sender.url === browser.extension.getURL(proxyScriptURL)) {    console.log(message);  }});let messageToProxy = {  enabled: true,  foo: "A string",  bar: 1234,};browser.runtime.sendMessage(messageToProxy, { toProxyScript: true });
js
// pac.jsbrowser.runtime.onMessage.addListener((message) => {  if (message.enabled) {    browser.runtime.sendMessage("I'm enabled!");  }});

PAC ファイル仕様

The basic PAC file syntax is described in thePAC documentation, but the implementation used by the proxy API differs from standard PAC design in several ways, which are described in this section.

FindProxyForURL() return value

The standardFindProxyForURL()returns a string. In Firefox 55 and 56, the PAC file used with the proxy API also returns a string. In Firefox 55only, you must pass an argument to the "DIRECT" return value, even though it doesn't need an argument.

From Firefox 57 onwards,FindProxyForURL() may still return a string, but may alternatively (and preferably) return an array of objects. Each object has the following properties:

type

String. This must be one of: "http"|"https|"socks4"|"socks"|"direct". "socks" refers to the SOCKS5 protocol.

host

String. Hostname for the proxy to use.

port

String. Port for the proxy.

username省略可

String. Username for the proxy. This is usable with "socks". For HTTP proxy authorizations, usewebRequest.onAuthRequired.

password省略可

String. Password for the proxy. This is usable with "socks". For HTTP proxy authorizations, usewebRequest.onAuthRequired.

proxyDNS省略可

Boolean. If true, the proxy server is used to resolve certain DNS queries (only usable with "socks4" and "socks"). Defaults tofalse.

failoverTimeout省略可

Integer. Number of seconds before timing out and trying the next proxy in the array. Defaults to 1.

例えば、:

js
const proxySpecification = [  {    type: "socks",    host: "foo.com",    port: 1080,    proxyDNS: true,    failoverTimeout: 5,  },  {    type: "socks",    host: "bar.com",    port: 1060,  },];

The first proxy in the array will be tried first. If it does not respond infailoverTimeout seconds, the next will be tried, until the end of the array is reached.

PAC ファイル環境

The global helper functions usually available for PAC files (isPlainHostName(),dnsDomainIs(), and so on) are not available.

Code running in the PAC file does not get access to:

js
//  pac.js// send the log message to the background scriptbrowser.runtime.sendMessage(`Proxy-blocker: blocked ${url}`);
js
// background-script.jsfunction handleMessage(message, sender) {  // only handle messages from the proxy script  if (sender.url != browser.extension.getURL(proxyScriptURL)) {    return;  }  console.log(message);}browser.runtime.onMessage.addListener(handleMessage);

関数

proxy.register()

所与のプロキシースクリプトを登録する

proxy.unregister()

プロキシースクリプトの登録を取り消す。

イベント

proxy.onProxyError

プロキシースクリプト実行している際にシステムがエラーに遭遇した時に発火します。

ブラウザーの互換性

Example extensions

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp