Skip to content

Commit c6fe25f

Browse files
m719Copilot
andauthored
fix: dia browser popup compatibility (#132)
Add a safe settings-page fallback when openOptionsPage is unavailable or fails. Make INJECT_ALL_TABS fire-and-forget in setup so the wizard does not block on slow tab injection responses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 82d6e5d commit c6fe25f

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/popup/hooks/usePopupActions.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,35 @@ export const usePopupActions = ({
272272
}
273273
}, [ensureContentScriptAndSendMessage, isPdfScannerPage]);
274274

275-
const handleOpenSettings = useCallback(() => {
276-
if (typeof chrome === 'undefined' || !chrome.runtime?.openOptionsPage) return;
277-
chrome.runtime.openOptionsPage();
275+
const openSettingsPage = useCallback(async () => {
276+
if (typeof chrome === 'undefined' || !chrome.runtime) return;
277+
278+
const optionsUrl = chrome.runtime.getURL('options/index.html');
279+
280+
try {
281+
if (chrome.runtime.openOptionsPage) {
282+
await chrome.runtime.openOptionsPage();
283+
return;
284+
}
285+
} catch (error) {
286+
log.warn('openOptionsPage failed, falling back to direct options URL:', error);
287+
}
288+
289+
try {
290+
if (chrome.tabs?.create) {
291+
await chrome.tabs.create({ url: optionsUrl });
292+
} else {
293+
window.open(optionsUrl, '_blank');
294+
}
295+
} catch (error) {
296+
log.error('Failed to open settings page:', error);
297+
}
278298
}, []);
279299

300+
const handleOpenSettings = useCallback(() => {
301+
void openSettingsPage();
302+
}, [openSettingsPage]);
303+
280304
const handleOpenPlatform = useCallback((url: string) => {
281305
if (typeof chrome === 'undefined' || !chrome.tabs) return;
282306
chrome.tabs.create({ url });
@@ -295,15 +319,13 @@ export const usePopupActions = ({
295319
}
296320

297321
if (hasEnterprise) {
298-
if (typeof chrome !== 'undefined' && chrome.runtime?.openOptionsPage) {
299-
chrome.runtime.openOptionsPage();
300-
}
322+
await openSettingsPage();
301323
window.close();
302324
return;
303325
}
304326

305327
setShowEETrialDialog(true);
306-
}, [aiConfigured, hasEnterprise, setShowEETrialDialog]);
328+
}, [aiConfigured, hasEnterprise, openSettingsPage, setShowEETrialDialog]);
307329

308330
return {
309331
ensureContentScriptAndSendMessage,
@@ -322,4 +344,3 @@ export const usePopupActions = ({
322344
};
323345

324346
export default usePopupActions;
325-

src/popup/hooks/useSetupWizard.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,17 @@ export const useSetupWizard = ({ setStatus }: UseSetupWizardProps): UseSetupWiza
272272
log.debug(`Settings saved successfully for ${platformType}, isEnterprise: ${isEnterprise}`);
273273

274274
setSetupSuccess(true);
275-
276-
// Inject content scripts into all open tabs
277-
try {
278-
await chrome.runtime.sendMessage({ type: 'INJECT_ALL_TABS' });
279-
} catch (error) {
275+
setSetupTesting(false);
276+
277+
// Inject content scripts into all open tabs without blocking setup flow.
278+
// Some environments/tabs may keep this message pending for too long.
279+
void chrome.runtime.sendMessage({ type: 'INJECT_ALL_TABS' }).catch((error) => {
280280
log.debug('Note: Could not inject content scripts into existing tabs:', error);
281-
}
281+
});
282282

283283
// Move to next step after a short delay
284-
setTimeout(async () => {
284+
setTimeout(() => {
285285
resetSetupForm();
286-
setSetupTesting(false);
287286

288287
if (platformType === 'opencti') {
289288
setSetupStepInternal('openaev');
@@ -327,4 +326,3 @@ export const useSetupWizard = ({ setStatus }: UseSetupWizardProps): UseSetupWiza
327326
};
328327

329328
export default useSetupWizard;
330-

0 commit comments

Comments
 (0)