fix: comprehensive extension context invalidated handling
Some checks failed
CI — Test & Build / Test & Build (push) Has been cancelled
Some checks failed
CI — Test & Build / Test & Build (push) Has been cancelled
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
|
||||
// ─── Safe chrome storage wrapper ─────────────────────────────────────────────
|
||||
|
||||
function safeStorageGet(keys: string[], callback: (result: Record<string, string>) => void) {
|
||||
try {
|
||||
if (typeof chrome === 'undefined' || !chrome.runtime?.id) return;
|
||||
chrome.storage.local.get(keys, callback);
|
||||
} catch (err) {
|
||||
console.warn('LexAI: Extension context invalidated', err);
|
||||
}
|
||||
}
|
||||
|
||||
function Popup() {
|
||||
const [configured, setConfigured] = useState(false);
|
||||
const [provider, setProvider] = useState('');
|
||||
const [model, setModel] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
chrome.storage.local.get(["provider", "apiKey", "model"], (result: Record<string, string>) => {
|
||||
safeStorageGet(["provider", "apiKey", "model"], (result) => {
|
||||
if (result.apiKey) {
|
||||
setConfigured(true);
|
||||
setProvider(result.provider || 'openai');
|
||||
@@ -16,7 +27,15 @@ function Popup() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const openSettings = () => chrome.runtime.openOptionsPage();
|
||||
const openSettings = () => {
|
||||
try {
|
||||
if (typeof chrome !== 'undefined' && chrome.runtime?.id) {
|
||||
chrome.runtime.openOptionsPage();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('LexAI: Extension context invalidated', err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: 16, fontFamily: 'system-ui, sans-serif', color: '#1e1e2e' }}>
|
||||
|
||||
Reference in New Issue
Block a user