gpt4 book ai didi

node.js - Electron .getWebContents()。on ('login',..)仅被调用一次

转载 作者:行者123 更新时间:2023-12-03 12:28:13 25 4
gpt4 key购买 nike

我正在尝试在webview元素上使用代理,但是当我尝试在已设置代理之后更改代理时,它将不会调用“登录”,而是第一次使用为代理提供的相同凭据。

代码:

newWebView.getWebContents().on('login', (event, request, authInfo, callback) => {
event.preventDefault();

if (authInfo.isProxy) {
console.log("Proxy set")
callback(username, password)
}
});

但是该代码仅被调用一次。

我什至激发了一个新的webview元素并设置了新的“login”事件,但是它仍然没有被解雇。

我的意思是,因为ip具有相同的端口和ip,它将保持默认凭据,但是我需要在webview中更改代理的身份验证凭据。

怎么办呢?

最佳答案

login要执行基本身份验证时,将发出该应用的webContents事件。

  const { app } = require('electron')
app.on("login", (event, webContents, request, authInfo, cb) =>
tryProxyLogin(webContents, event, request, authInfo, cb)
);

/**
*
* @param {Electron.webContents} webContents
* @param {Electron.Event} event
* @param {Electron.Request} request
* @param {Electron.AuthInfo} authInfo
* @param {(username:string,password:string)=>void} cb
*/
const tryProxyLogin = (webContents, event, request, authInfo, cb) => {
try {
const contentId = webContents.id;

const { username, password } = {
username: XXXXX,
password: XXXXX
};

if (authInfo.isProxy && username && password) {

//temp solution about this issue
//https://github.com/electron/electron/issues/16010

if (!authInfo.realm) {
setTimeout(() => {
webContents.reload();
}, 500);
return;
}

const { country, sessionId } = {
country: 'XXXXX',
sessionID: 'xxxxxxx-xxxxxxx'
};

if (country && sessionId) {
event.preventDefault();
console.debug(
"proxy ready to login",
`customer-${username}-cc-${country}-sessid-${sessionId}`
);

cb(
`customer-${username}-cc-${country}-sessid-${sessionId}-${Date.now()}`,
password
);
}
}
} catch (error) {
console.error(error);
}
};

这基于Electron v4.2.0

关于node.js - Electron <webview> .getWebContents()。on ('login',..)仅被调用一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59462265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com