Verified Commit 424c7424 authored by Vincent's avatar Vincent

Fix not being able to detect the active tab

When multiple windows were open, the number of active tabs can be
more than 1, and the popover might not be communicating with the
correct one. This commit fixes that.
parent c10698fe
......@@ -9,7 +9,15 @@ const baseUrl = (typeof process.env.APP_URL === 'string' && process.env.APP_URL
: 'https://plaudit.pub';
document.addEventListener('DOMContentLoaded', async () => {
const activeTabs = await browser.tabs.query({ active: true });
const activeTabs = await browser.tabs.query({
active: true,
currentWindow: true,
discarded: false,
});
if (activeTabs.length !== 1) {
// Only run if we can determine the current tab
return;
}
const response = await browser.tabs.sendMessage<ExtensionMessage>(
activeTabs[0].id,
{ type: 'requestDoi' },
......
declare module 'webextension-polyfill' {
export default browser;
}
type TabStatus = 'loading' | 'complete';
interface Tab {
id: number;
active: boolean;
......@@ -26,7 +27,10 @@ declare namespace browser.tabs {
export function query(queryInfo: Partial<{
active: boolean;
currentWindow: boolean;
discarded: boolean;
index: number;
status: TabStatus;
title: string;
url: string;
}>): Promise<Tab[]>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment