//这个方法是对上面方法的优化,可以随变量的变化多次运行,运行成功时,返回弹窗的([内容,网址,类型])数组,可能用到的时候较少
async function 弹窗关闭2(e) {
let {target: t, commandParams: o} = e
, n = await Pe(t)
, a = !1;
try {
(a = (await chrome.debugger.getTargets()).some( (u) => u.tabId === n.tabId && u.attached, )),
a || (await chrome.debugger.attach(n, "1.3"));
let dd;
if(chrome.debugger.bb==null){
chrome.debugger.sendCommand(n, 'Page.enable');
chrome.debugger.bb=1;
chrome.debugger.onEvent.addListener(function(source, message, params) {if (message === "Page.javascriptDialogOpening") {chrome.debugger.aa=[params.message,params.url,params.type]}});
dd=false;}
if(chrome.debugger.aa){
dd=chrome.debugger.aa;
chrome.debugger.sendCommand(n,"Page.handleJavaScriptDialog",o);
chrome.debugger.aa=null;}else{dd=false;}
return a || (await chrome.debugger.detach(n)),dd
} catch (s) {
if (!a)
try {
await chrome.debugger.detach(n)
} catch (l) {
console.error("\u5206\u79BB\u8C03\u8BD5\u5668\u65F6\u51FA\u9519:", l)
}
throw s;
}
}
//参数说明
target: 调试目标----{"tabId": 824089761}
commandParams:弹窗关闭 -----确定按钮("accept": true) 取消按钮("accept": false) 设置内容("promptText": "1111")只对prompt框起作用
//参数示例
{
"target": {"tabId": 824089761},
"commandParams":{"accept": true,"promptText": ""}
}