@@ -16,6 +16,7 @@ import { listRunningProcesses, windowsClose, waitForExit } from '../util/process
16
16
import { HideWarningServer } from '../hide-warning-server' ;
17
17
import { Interceptor } from '.' ;
18
18
import { reportError } from '../error-tracking' ;
19
+ import { WEBEXTENSION_PATH } from '../webextension' ;
19
20
20
21
const getBrowserDetails = async ( config : HtkConfig , variant : string ) : Promise < Browser | undefined > => {
21
22
const browsers = await getAvailableBrowsers ( config . configPath ) ;
@@ -28,7 +29,8 @@ const getChromiumLaunchOptions = async (
28
29
browser : string ,
29
30
config : HtkConfig ,
30
31
proxyPort : number ,
31
- hideWarningServer : HideWarningServer
32
+ hideWarningServer : HideWarningServer ,
33
+ webExtensionEnabled : boolean
32
34
) : Promise < LaunchOptions & { options : Required < LaunchOptions > [ 'options' ] } > => {
33
35
const certificatePem = await readFile ( config . https . certPath , 'utf8' ) ;
34
36
const spkiFingerprint = generateSPKIFingerprint ( certificatePem ) ;
@@ -42,7 +44,11 @@ const getChromiumLaunchOptions = async (
42
44
'<-loopback>' ,
43
45
// Don't intercept our warning hiding requests. Note that this must be
44
46
// the 2nd rule here, or <-loopback> would override it.
45
- hideWarningServer . host
47
+ hideWarningServer . host ,
48
+ // We use httptoolkit-internal.localhost (always resolves to localhost,
49
+ // enforced by Chrome) to skip the proxy for internal requests from the
50
+ // our webextension.
51
+ 'internal.httptoolkit.localhost'
46
52
] ,
47
53
options : [
48
54
// Trust our CA certificate's fingerprint:
@@ -52,7 +58,16 @@ const getChromiumLaunchOptions = async (
52
58
// Avoid annoying extra network noise:
53
59
'--disable-background-networking' ,
54
60
'--disable-component-update' ,
55
- '--check-for-update-interval=31536000' // Don't update for a year
61
+ '--check-for-update-interval=31536000' , // Don't update for a year
62
+ ...( webExtensionEnabled
63
+ // Install HTTP Toolkit's extension, for advanced hook setup. Feature
64
+ // flagged for now as it's still new & largely untested.
65
+ ? [
66
+
67
+ `--load-extension=${ WEBEXTENSION_PATH } `
68
+ ]
69
+ : [ ]
70
+ )
56
71
]
57
72
} ;
58
73
}
@@ -80,7 +95,7 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
80
95
return ! ! browserDetails ;
81
96
}
82
97
83
- async activate ( proxyPort : number ) {
98
+ async activate ( proxyPort : number , options : { webExtensionEnabled ?: boolean } = { } ) {
84
99
if ( this . isActive ( proxyPort ) ) return ;
85
100
86
101
const hideWarningServer = new HideWarningServer ( this . config ) ;
@@ -93,7 +108,8 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
93
108
browserDetails ? browserDetails . name : this . variantName ,
94
109
this . config ,
95
110
proxyPort ,
96
- hideWarningServer
111
+ hideWarningServer ,
112
+ ! ! options . webExtensionEnabled
97
113
)
98
114
, this . config . configPath ) ;
99
115
@@ -220,7 +236,10 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
220
236
return defaultRootProcess && defaultRootProcess . pid ;
221
237
}
222
238
223
- async activate ( proxyPort : number , options : { closeConfirmed : boolean } = { closeConfirmed : false } ) {
239
+ async activate ( proxyPort : number , options : {
240
+ closeConfirmed : boolean ,
241
+ webExtensionEnabled ?: boolean
242
+ } = { closeConfirmed : false } ) {
224
243
if ( ! this . isActivable ( ) ) return ;
225
244
226
245
const hideWarningServer = new HideWarningServer ( this . config ) ;
@@ -257,7 +276,8 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
257
276
browserDetails ? browserDetails . name : this . variantName ,
258
277
this . config ,
259
278
proxyPort ,
260
- hideWarningServer
279
+ hideWarningServer ,
280
+ ! ! options . webExtensionEnabled
261
281
) ;
262
282
263
283
// Remove almost all default arguments. Each of these changes behaviour in maybe unexpected
0 commit comments