From aa83ccae876c1911aaa6fea2f7874afde4e4106c Mon Sep 17 00:00:00 2001 From: luckyrat Date: Fri, 2 Feb 2018 00:01:39 +0000 Subject: [PATCH] Auto-fill HTTP Proxies --- background/NetworkAuth.ts | 16 ++++++++- manifest.json | 3 +- typedefs/browser.d.ts | 71 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/background/NetworkAuth.ts b/background/NetworkAuth.ts index aecd7fed..5b42eb50 100644 --- a/background/NetworkAuth.ts +++ b/background/NetworkAuth.ts @@ -44,7 +44,21 @@ export class NetworkAuth { return { cancel: false }; } - const url = new URL(requestDetails.url); + let originalUrl; + + if (requestDetails.isProxy) { + if (requestDetails.proxyInfo) { + // Firefox + originalUrl = requestDetails.proxyInfo.host; + } else { + // Chrome + originalUrl = requestDetails.challenger.host; + } + } else { + originalUrl = requestDetails.url; + } + + const url = new URL(originalUrl); url.hostname = punycode.toUnicode(url.hostname); const result = await window.kee.findLogins( diff --git a/manifest.json b/manifest.json index fd1dccb7..5f691e18 100644 --- a/manifest.json +++ b/manifest.json @@ -100,7 +100,8 @@ "", "notifications", "unlimitedStorage", - "idle" + "idle", + "proxy" ], "web_accessible_resources" : [ "panels/*" diff --git a/typedefs/browser.d.ts b/typedefs/browser.d.ts index 405a19a2..a8b68d1b 100644 --- a/typedefs/browser.d.ts +++ b/typedefs/browser.d.ts @@ -4665,6 +4665,77 @@ declare namespace browser.webRequest { type OnCompletedOptions = "responseHeaders"; + interface ResourceRequest { + url: string; + /** The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request. */ + requestId: string; + /** The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (type is main_frame or sub_frame), frameId indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab. */ + frameId: number; + /** ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists. */ + parentFrameId: number; + /** The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab. */ + tabId: number; + /** + * How the requested resource will be used. + * One of: "main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", or "other" + */ + type: string; + /** The time when this signal is triggered, in milliseconds since the epoch. */ + timeStamp: number; + } + + interface WebResponseDetails extends ResourceRequest { + /** HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line). */ + statusLine: string; + /** + * Standard HTTP status code returned by the server. + * @since Chrome 43. + */ + statusCode: number; + } + + interface WebResponseHeadersDetails extends WebResponseDetails { + /** Optional. The HTTP response headers that have been received with this response. */ + responseHeaders?: HttpHeaders; + method: string; /** standard HTTP method i.e. GET, POST, PUT, etc. */ + } + + interface WebAuthChallenger { + host: string; + port: number; + } + + interface ProxyInfo { + host: string; + port: number; + type: string; + /* One of: + + "http": HTTP proxy (or SSL CONNECT for HTTPS) + "https": HTTP proxying over TLS connection to proxy + "socks": SOCKS v5 proxy + "socks4": SOCKS v4 proxy + "direct": no proxy + "unknown": unknown proxy + */ + username: string; + proxyDNS: boolean; + failoverTimeout: number; + } + + interface WebAuthenticationChallengeDetails extends WebResponseHeadersDetails { + /** The authentication scheme, e.g. Basic or Digest. */ + scheme: string; + /** The authentication realm provided by the server, if there is one. */ + realm?: string; + /** The server requesting authentication. In Chrome, host is the proxy host if isProxy is true */ + challenger: WebAuthChallenger; + /** True for Proxy-Authenticate, false for WWW-Authenticate. */ + isProxy: boolean; + /** Firefox only. This property is present only if the request is being proxied. */ + proxyInfo?: ProxyInfo; + } + /** An object describing filters to apply to webRequest events. */ interface RequestFilter { /** A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out. */