[FIX] devtools: fix display and message passing for firefox

This commit fixes 2 issues specific to the firefox version of the
extension:
First issue concerns the computation the position of the
border between the subwindows of the components tab which could go
terribly wrong due to the fact that the innerwidth of the window is
implicitly set to 10 when the owl devtools window is hidden.
Second issue comes from changes in the runtime.onMessage method of
browser which now requires to directly return the response instead of
using the sendResponse method.
Also perform a little cleanup on usage of browserInstance and in the
manifest.
This commit is contained in:
Julien Carion (juca)
2023-10-18 13:31:57 +02:00
committed by Géry Debongnie
parent fee3eecd7f
commit fb013ccc72
8 changed files with 20 additions and 24 deletions
+7 -7
View File
@@ -1,9 +1,7 @@
import { IS_FIREFOX, getActiveTabURL } from "./utils";
import { IS_FIREFOX, getActiveTabURL, browserInstance } from "./utils";
let owlStatus = 0;
const browserInstance = IS_FIREFOX ? browser : chrome;
// Used to keep track of the tabs where the owl devtools have been opened
const activePanels = new Map();
@@ -71,6 +69,9 @@ function checkOwlStatus(tabId) {
browserInstance.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
// Send back the owl status to the sender
if (message.type === "getOwlStatus") {
if (IS_FIREFOX) {
return { result: owlStatus };
}
sendResponse({ result: owlStatus });
return true;
} else if (message.type === "owlStatus") {
@@ -112,11 +113,10 @@ browserInstance.runtime.onMessage.addListener(async (message, sender, sendRespon
}, 750);
activePanels.set(message.id, { port: port, expirationTimeout: expirationTimeout });
// This is solely for firefox which doesnt allow access to the chrome.tabs api inside devtools
// We therefore only use the firefox syntax to send the response here
} else if (message.type === "getActiveTabURL") {
getActiveTabURL().then((tab) => {
sendResponse({ result: tab });
});
return true;
const tab = await getActiveTabURL();
return { result: tab };
} else {
const destinationPanel = activePanels.get(sender.tab.id);
if (destinationPanel) {