(tabId, rect)
| 4202 | } |
| 4203 | |
| 4204 | async function clickWithDebugger(tabId, rect) { |
| 4205 | throwIfStopped(); |
| 4206 | if (!tabId) { |
| 4207 | throw new Error('未找到用于调试点击的认证页面标签页。'); |
| 4208 | } |
| 4209 | if (!rect || !Number.isFinite(rect.centerX) || !Number.isFinite(rect.centerY)) { |
| 4210 | throw new Error('步骤 8 的调试器兜底点击需要有效的按钮坐标。'); |
| 4211 | } |
| 4212 | |
| 4213 | const target = { tabId }; |
| 4214 | try { |
| 4215 | await chrome.debugger.attach(target, '1.3'); |
| 4216 | } catch (err) { |
| 4217 | throw new Error( |
| 4218 | `步骤 8 的调试器兜底点击附加失败:${err.message}。` + |
| 4219 | '如果认证页标签已打开 DevTools,请先关闭后重试。' |
| 4220 | ); |
| 4221 | } |
| 4222 | |
| 4223 | try { |
| 4224 | throwIfStopped(); |
| 4225 | const x = Math.round(rect.centerX); |
| 4226 | const y = Math.round(rect.centerY); |
| 4227 | |
| 4228 | await chrome.debugger.sendCommand(target, 'Page.bringToFront'); |
| 4229 | throwIfStopped(); |
| 4230 | await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', { |
| 4231 | type: 'mouseMoved', |
| 4232 | x, |
| 4233 | y, |
| 4234 | button: 'none', |
| 4235 | buttons: 0, |
| 4236 | clickCount: 0, |
| 4237 | }); |
| 4238 | throwIfStopped(); |
| 4239 | await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', { |
| 4240 | type: 'mousePressed', |
| 4241 | x, |
| 4242 | y, |
| 4243 | button: 'left', |
| 4244 | buttons: 1, |
| 4245 | clickCount: 1, |
| 4246 | }); |
| 4247 | throwIfStopped(); |
| 4248 | await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', { |
| 4249 | type: 'mouseReleased', |
| 4250 | x, |
| 4251 | y, |
| 4252 | button: 'left', |
| 4253 | buttons: 0, |
| 4254 | clickCount: 1, |
| 4255 | }); |
| 4256 | } finally { |
| 4257 | await chrome.debugger.detach(target).catch(() => { }); |
| 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | async function broadcastStopToContentScripts() { |
no test coverage detected