unable to get the message through

This commit is contained in:
Dhravya Shah 2025-02-18 20:43:29 -07:00
parent a1b3a1f223
commit f6c2e220a3
6 changed files with 32 additions and 12 deletions

View file

@ -31,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",

View file

@ -154,7 +154,6 @@ registerMessageHandler<MessageType>(
target: { tabId: currentTab.id },
files: ["scripts/content.js"],
});
} catch (error) {
console.error("Error injecting content script:", error);
}

View file

@ -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);

View file

@ -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 {
@ -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 ||
@ -465,6 +465,6 @@ export const setupTwitterHeaderListener = () => {
}
},
{ urls: ["*://x.com/*", "*://twitter.com/*"] },
["requestHeaders", "extraHeaders"]
extraOptions
);
};

View file

@ -98,6 +98,7 @@ export const getIntegrations = (
console.log("Response:", response);
},
);
await window.postMessage({ action: "exportBookmarks" }, "*");
console.log("Message sent");
},

View file

@ -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",