feat: 添加密码管理功能,包括 API、数据库支持和前端界面
This commit is contained in:
21
apps/extension/src/background.js
Normal file
21
apps/extension/src/background.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const PENDING_KEY = "bb_pending_credential";
|
||||
const PENDING_TAB_KEY = "bb_pending_tab_id";
|
||||
|
||||
function openPopup() {
|
||||
if (typeof chrome === "undefined" || !chrome.action?.openPopup) return;
|
||||
chrome.action.openPopup().catch(() => {
|
||||
// ignore if popup cannot be opened (no user gesture)
|
||||
});
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((msg, sender) => {
|
||||
if (!msg || msg.type !== "CREDENTIAL_CAPTURED") return;
|
||||
|
||||
const payload = msg.payload || {};
|
||||
chrome.storage.local.set({
|
||||
[PENDING_KEY]: payload,
|
||||
[PENDING_TAB_KEY]: sender?.tab?.id || null
|
||||
}, () => {
|
||||
openPopup();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user