Skip to content

Commit

Permalink
Merge pull request #115 from rodolfomiranda/firefox
Browse files Browse the repository at this point in the history
Support for firefox
  • Loading branch information
rodolfomiranda committed Feb 29, 2024
2 parents 569db83 + 05974fc commit b0ecc85
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/pages/background/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const senderIsPopup = (sender: chrome.runtime.MessageSender) => {
const origin = "chrome-extension://" + chrome.runtime.id;
const popupPath = origin + "/src/pages/popup/index.html";
return sender.origin === origin && sender.url === popupPath;
return ((sender.url?.startsWith('moz-extension://') || sender.url?.startsWith('chrome-extension://'))&&
sender.url?.endsWith('/src/pages/popup/index.html') &&
sender.id === chrome.runtime.id);
};

export const isValidUrl = (str: string) => {
Expand Down
11 changes: 8 additions & 3 deletions src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ window.addEventListener(
});

let filteredSignins: any[] = [];
console.log(event.data.type);
tabSigninResp?.data?.signins.forEach((signin: any) => {
if (
signin.identifier &&
Expand Down Expand Up @@ -98,7 +97,8 @@ chrome.runtime.onMessage.addListener(async function (
sender,
sendResponse
) {
if (sender.origin === "chrome-extension://" + chrome.runtime.id) {
if ((sender.url?.startsWith("moz-extension://") || sender.origin?.startsWith("chrome-extension://")) &&
sender.id === chrome.runtime.id) {
console.log(
"Message received from browser extension: " +
message.type +
Expand Down Expand Up @@ -135,7 +135,12 @@ chrome.runtime.onMessage.addListener(async function (
}

if (message.type === "tab" && message.subtype === "get-tab-state") {
sendResponse({ data: { appState: getTabState() } });
if (sender.origin?.startsWith("chrome-extension://")){
sendResponse({ data: { appState: getTabState() } });
} else {
return Promise.resolve({ data: { appState: getTabState() } })
}

}

if (message.type === "tab" && message.subtype === "set-tab-state") {
Expand Down
1 change: 0 additions & 1 deletion src/pages/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default function Popup(): JSX.Element {
if (data.isConnected) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (tabs.length === 1) {
console.log("realoading tab");
chrome.tabs.sendMessage(tabs[0].id!, {
type: "tab",
subtype: "reload-state",
Expand Down
8 changes: 3 additions & 5 deletions src/pages/popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ function init() {
sender,
sendResponse
) {
if (
sender.url ===
"chrome-extension://" +
chrome.runtime.id +
"/service-worker-loader.js" &&
if ((sender.url?.startsWith('moz-extension://') || sender.url?.startsWith('chrome-extension://')) &&
sender.url?.endsWith('/service-worker-loader.js') &&
sender.id === chrome.runtime.id &&
request.type === "popup" &&
request.subtype === "isOpened"
) {
Expand Down

0 comments on commit b0ecc85

Please sign in to comment.