Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ Step 3 使用的注册邮箱。

- 自动填写 localhost 回调地址
- 自动点击“提交回调 URL”
- 即使 CPA 面板本身部署在 `localhost` / `127.0.0.1`,也不会跳过这一步
- 必须等到 CPA 面板出现精确的 `认证成功!` 状态徽标后,才判定成功
- 成功后会自动关闭匹配 `http://localhost:1455/auth` 这一类前缀的 localhost 残留页面

Expand Down
15 changes: 14 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ function isLocalCpaUrl(rawUrl) {
}

function shouldBypassStep9ForLocalCpa(state) {
return Boolean(state?.localhostUrl) && isLocalCpaUrl(state?.vpsUrl);
// 即使 CPA 面板本身部署在 localhost,也必须显式执行步骤 9:
// 回填 callback URL、点击提交,并等待面板出现“认证成功!”。
// 否则会出现步骤 8 捕获到 localhost 后流程直接结束的问题。
return false;
}

function matchesSourceUrlFamily(source, candidateUrl, referenceUrl) {
Expand Down Expand Up @@ -1179,6 +1182,8 @@ async function humanStepDelay(min = HUMAN_STEP_DELAY_MIN, max = HUMAN_STEP_DELAY
}

async function clickWithDebugger(tabId, rect) {
throwIfStopped();

if (!tabId) {
throw new Error('未找到用于调试点击的认证页面标签页。');
}
Expand All @@ -1197,10 +1202,14 @@ async function clickWithDebugger(tabId, rect) {
}

try {
throwIfStopped();

const x = Math.round(rect.centerX);
const y = Math.round(rect.centerY);

await chrome.debugger.sendCommand(target, 'Page.bringToFront');
throwIfStopped();

await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
type: 'mouseMoved',
x,
Expand All @@ -1209,6 +1218,8 @@ async function clickWithDebugger(tabId, rect) {
buttons: 0,
clickCount: 0,
});
throwIfStopped();

await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
type: 'mousePressed',
x,
Expand All @@ -1217,6 +1228,8 @@ async function clickWithDebugger(tabId, rect) {
buttons: 1,
clickCount: 1,
});
throwIfStopped();

await chrome.debugger.sendCommand(target, 'Input.dispatchMouseEvent', {
type: 'mouseReleased',
x,
Expand Down
2 changes: 1 addition & 1 deletion tests/step9-cpa-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ assert.strictEqual(api.isLocalCpaUrl('notaurl'), false, '非法 URL 不应视为
assert.strictEqual(api.shouldBypassStep9ForLocalCpa({
vpsUrl: 'http://127.0.0.1:8317/management.html#/oauth',
localhostUrl: 'http://127.0.0.1:8317/codex/callback?code=abc&state=xyz',
}), true, '本地 CPA 且已有 callback 时应跳过远程提交流程');
}), false, '即使 CPA 在本地,也不应跳过步骤 9 的回填提交流程');

assert.strictEqual(api.shouldBypassStep9ForLocalCpa({
vpsUrl: 'https://example.com/management.html#/oauth',
Expand Down
Loading