Files
HomeDash/extension/firefox/options.js
JianFeeeee 63c588145b fix(extension): 同步失败时真实原因被吞成「失败: undefined」
background 的「未配置站点」分支只返回 {ok:false, reason:'not configured'},
而 options.js 只读 result.error || result.status —— 两个字段都没有,
于是模板插值出 undefined,用户看到「失败: undefined」,真实原因看不到。
实测服务端日志里没有任何 /api/history/sync 请求,确认请求根本没发出。

修:两版 options.js 改为 error || reason || status || '未知错误',
两版 background.js 的 reason 换成中文可操作提示
「未配置站点地址,请先填写并保存」。
firefox 版本升到 1.1.4(已签名的 1.1.3 内容已冻结,须重签)。
2026-10-03 08:28:26 +08:00

42 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const api = typeof browser !== 'undefined' ? browser : chrome;
const urlInput = document.getElementById('url');
const tokenInput = document.getElementById('token');
const deviceInput = document.getElementById('device');
const status = document.getElementById('status');
api.runtime.sendMessage({ action: 'getConfig' }, (config) => {
urlInput.value = config.serverUrl || '';
tokenInput.value = config.syncToken || '';
deviceInput.value = config.deviceName || '';
});
document.getElementById('save').addEventListener('click', () => {
api.runtime.sendMessage({
action: 'setConfig',
data: {
serverUrl: urlInput.value.replace(/\/$/, ''),
syncToken: tokenInput.value,
deviceName: deviceInput.value,
},
}, () => { status.textContent = '已保存'; });
});
document.getElementById('sync').addEventListener('click', () => {
api.runtime.sendMessage({ action: 'sync' }, (result) => {
if (!result) {
status.textContent = '失败: 扩展后台无响应';
return;
}
status.textContent = result.skipped
? '无待同步'
: result.ok
? `同步 ${result.count} 条,共 ${result.total}`
// 后台各条失败路径给的字段不一致(reason / error / status),
// 以前只读 error 和 status,于是「未配置站点」这种返回会显示成
// 「失败: undefined」——真实原因被吞掉,只剩一个无意义的报错。
: `失败: ${result.error || result.reason || result.status || '未知错误'}`;
});
});