Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firefox support #333

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"bookmarks"
],
"host_permissions": ["*://*/*"],
"background": {
"chromium:background": {
"service_worker": "src/background.ts"
},
"firefox:background": {
"scripts": ["src/background.ts"]
},
"action": {},
"externally_connectable": {
"matches": [
Expand All @@ -28,6 +31,16 @@
"http://supermemory.com/*"
]
},
"firefox:content_scripts": [{
"matches": [
"http://localhost:3000/*",
"https://supermemory.ai/*",
"https://beta.supermemory.ai/*",
"http://supermemory.com/*"
],
"js": ["src/firefox/content.ts"]
}
],
"icons": {
"16": "images/icon/16.png",
"32": "images/icon/32.png",
Expand Down
10 changes: 7 additions & 3 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
"type": "module",
"scripts": {
"dev:css": "npx tailwindcss -i css/globals.css -o public/globals.css --watch",
"dev:extension": "extension dev",
"dev:extension": "extension dev --chromium",
"dev:firefox": "extension dev --browser firefox --polyfill",
"dev": "concurrently \"npm:dev:css\" \"npm:dev:extension\"",
"build:css": "npx tailwindcss -i css/globals.css -o public/globals.css",
"build:extension": "extension build",
"build:extension": "extension build --chromium",
"build:extension:firefox": "extension build --browser firefox --polyfill",
"build": "npm run build:css && npm run build:extension",
"build:firefox": "npm run build:css && npm run build:extension:firefox",
"start": "npm run build && extension start",
"zip": "zip -r supermemory-extension.zip ./dist/chrome/*"
"zip": "cd dist/chrome && zip -r supermemory-extension.zip .",
"zip:firefox": "cd dist/firefox && zip -r supermemory-extension.zip ."
},
"dependencies": {
"@mozilla/readability": "^0.5.0",
Expand Down
1 change: 0 additions & 1 deletion apps/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ registerMessageHandler<MessageType>(
target: { tabId: currentTab.id },
files: ["scripts/content.js"],
});

} catch (error) {
console.error("Error injecting content script:", error);
}
Expand Down
9 changes: 9 additions & 0 deletions apps/extension/src/firefox/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const handleWindowMessage = (event: MessageEvent) => {
if (event.data.action === "exportBookmarks") {
console.log("Received exportBookmarks message via postMessage");
chrome.runtime.sendMessage({ action: "exportBookmarks" });
}
};

window.addEventListener("message", handleWindowMessage);

22 changes: 11 additions & 11 deletions apps/extension/src/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ const getBookmarks = async (cursor = "", totalImported = 0, allTweets = []) => {
};

export const setupTwitterHeaderListener = () => {
const extraOptions =
chrome.runtime.getManifest().manifest_version === 2
? ["blocking", "requestHeaders"]
: ["requestHeaders"];

// Add extraHeaders only if we're on a Chromium-based browser
if (!navigator.userAgent.includes("Firefox")) {
extraOptions.push("extraHeaders");
}

chrome.webRequest.onBeforeSendHeaders.addListener(
(details) => {
try {
Expand Down Expand Up @@ -426,16 +436,6 @@ export const setupTwitterHeaderListener = () => {
const cookie = getHeaderValue("cookie");
const csrf = getHeaderValue("x-csrf-token");

// // Validate required headers
// if (!auth || !cookie || !csrf) {
// console.warn("Missing required headers", {
// hasAuth: !!auth,
// hasCookie: !!cookie,
// hasCsrf: !!csrf,
// });
// return;
// }

// Only update storage if values have changed
if (
result.cookie !== cookie ||
Expand Down Expand Up @@ -465,6 +465,6 @@ export const setupTwitterHeaderListener = () => {
}
},
{ urls: ["*://x.com/*", "*://twitter.com/*"] },
["requestHeaders", "extraHeaders"]
extraOptions
);
};
1 change: 1 addition & 0 deletions apps/web/app/config/integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const getIntegrations = (
console.log("Response:", response);
},
);
await window.postMessage({ action: "exportBookmarks" }, "*");
console.log("Message sent");
},

Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@supermemory/db": "workspace:*",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/better-sqlite3": "^7.6.11",
"@types/firefox": "^0.0.34",
"@types/prismjs": "^1.26.5",
"@types/react-virtualized": "^9.21.30",
"@udecode/cn": "^39.0.0",
Expand Down