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 内容已冻结,须重签)。
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
'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 || '未知错误'}`;
|
||
});
|
||
});
|