mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-22 14:48:28 +00:00
feat: proxy rules with --proxy-rules
flag (#854)
See https://electronjs.org/docs/api/session?q=proxy#sessetproxyconfig-callback
This commit is contained in:
parent
84f06e3e79
commit
ef13ff1e1d
@ -75,6 +75,15 @@ function clearCache(browserWindow, targetUrl = null) {
|
||||
});
|
||||
}
|
||||
|
||||
function setProxyRules(browserWindow, proxyRules) {
|
||||
browserWindow.webContents.session.setProxy(
|
||||
{
|
||||
proxyRules,
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{}} inpOptions AppArgs from nativefier.json
|
||||
@ -284,6 +293,11 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
|
||||
if (options.userAgent) {
|
||||
window.webContents.setUserAgent(options.userAgent);
|
||||
}
|
||||
|
||||
if (options.proxyRules) {
|
||||
setProxyRules(window, options.proxyRules);
|
||||
}
|
||||
|
||||
maybeInjectCss(window);
|
||||
sendParamsOnDidFinishLoad(window);
|
||||
window.webContents.on('new-window', onNewWindow);
|
||||
@ -318,6 +332,10 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
|
||||
mainWindow.webContents.setUserAgent(options.userAgent);
|
||||
}
|
||||
|
||||
if (options.proxyRules) {
|
||||
setProxyRules(mainWindow, options.proxyRules);
|
||||
}
|
||||
|
||||
maybeInjectCss(mainWindow);
|
||||
sendParamsOnDidFinishLoad(mainWindow);
|
||||
|
||||
|
16
docs/api.md
16
docs/api.md
@ -43,6 +43,7 @@
|
||||
- [[enable-es3-apis]](#enable-es3-apis)
|
||||
- [[insecure]](#insecure)
|
||||
- [[internal-urls]](#internal-urls)
|
||||
- [[proxy-rules]](#proxy-rules)
|
||||
- [[flash]](#flash)
|
||||
- [[flash-path]](#flash-path)
|
||||
- [[disk-cache-size]](#disk-cache-size)
|
||||
@ -378,6 +379,21 @@ Or, if you want to allow all domains for example for external auths,
|
||||
nativefier https://google.com --internal-urls ".*?"
|
||||
```
|
||||
|
||||
|
||||
#### [proxy-rules]
|
||||
|
||||
```
|
||||
--proxy-rules <value>
|
||||
```
|
||||
|
||||
Proxy rules. See [proxyRules](https://electronjs.org/docs/api/session?q=proxy#sessetproxyconfig-callback) for more details.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
nativefier https://google.com --proxy-rules http://127.0.0.1:1080
|
||||
```
|
||||
|
||||
#### [flash]
|
||||
|
||||
```
|
||||
|
@ -42,6 +42,7 @@ function selectAppArgs(options) {
|
||||
disableDevTools: options.disableDevTools,
|
||||
zoom: options.zoom,
|
||||
internalUrls: options.internalUrls,
|
||||
proxyRules: options.proxyRules,
|
||||
crashReporter: options.crashReporter,
|
||||
singleInstance: options.singleInstance,
|
||||
clearCache: options.clearCache,
|
||||
|
@ -200,6 +200,10 @@ if (require.main === module) {
|
||||
'--internal-urls <value>',
|
||||
'regular expression of URLs to consider "internal"; all other URLs will be opened in an external browser. (default: URLs on same second-level domain as app)',
|
||||
)
|
||||
.option(
|
||||
'--proxy-rules <value>',
|
||||
'proxy rules. See https://electronjs.org/docs/api/session?q=proxy#sessetproxyconfig-callback',
|
||||
)
|
||||
.option(
|
||||
'--crash-reporter <value>',
|
||||
'remote server URL to send crash reports',
|
||||
|
@ -58,6 +58,7 @@ export default function(inpOptions) {
|
||||
tmpdir: false,
|
||||
zoom: inpOptions.zoom || 1.0,
|
||||
internalUrls: inpOptions.internalUrls || null,
|
||||
proxyRules: inpOptions.proxyRules || null,
|
||||
singleInstance: inpOptions.singleInstance || false,
|
||||
clearCache: inpOptions.clearCache || false,
|
||||
appVersion: inpOptions.appVersion,
|
||||
|
Loading…
x
Reference in New Issue
Block a user