Skip to content

Commit 2b5ac37

Browse files
committed
Fix bug: Login with token
The issue was in addListener. We had no sender and sendResponse defined and thus the channel auto-closed without ack. This fixes the bug and adds some debugging for future issues. Closes #62
1 parent 22b5fa3 commit 2b5ac37

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

content.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
// It will get the credentials via message passing from the popup
44
// It is also responsible to copy strings to the clipboard
55

6-
browser.runtime.onMessage.addListener((request) => {
6+
console.log('VaultPass: Content script loaded');
7+
8+
// We need sender and sendResponse so that the async communication works
9+
// otherwise users cannot login to vault using their token
10+
// eslint-disable-next-line no-unused-vars
11+
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
712
switch (request.message) {
813
case 'copy_to_clipboard':
914
handleCopyToClipboard(request);
@@ -17,8 +22,12 @@ browser.runtime.onMessage.addListener((request) => {
1722
break;
1823
case 'fetch_token':
1924
handleFetchToken();
25+
// If handleFetchToken is async or needs to send a response back,
26+
// we should handle it here. For now, it sends a message back to runtime.
2027
break;
2128
}
29+
// Return false because we don't need to keep the message channel open for an async response
30+
return false;
2231
});
2332

2433
function handleCopyToClipboard(request) {

options.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,27 @@ async function tokenGrabberClick() {
311311
currentWindow: true,
312312
});
313313

314+
console.log('TokenGrabber: Target Tab', currentTab);
315+
316+
if (!currentTab) {
317+
notify.error('No active tab found.');
318+
return;
319+
}
320+
321+
// Check if we are trying to grab token from the options page itself
322+
if (
323+
currentTab.url &&
324+
(currentTab.url.startsWith('moz-extension://') ||
325+
currentTab.url.startsWith('chrome-extension://'))
326+
) {
327+
notify
328+
.clear()
329+
.error(
330+
'You are on the Options page. Please go to the Vault tab, click the extension icon, click "Options", and then click "Get Token".'
331+
);
332+
return;
333+
}
334+
314335
try {
315336
await browser.tabs.sendMessage(currentTab.id, { message: 'fetch_token' });
316337
} catch (err) {
@@ -326,7 +347,8 @@ async function tokenGrabberClick() {
326347
);
327348
return;
328349
} else {
329-
notify.clear().error(err.message);
350+
console.error('TokenGrabber Error:', err);
351+
notify.clear().error(`Error contacting Vault tab: ${err.message}`);
330352
}
331353
}
332354
}

0 commit comments

Comments
 (0)