Skip to content

Commit 481c80c

Browse files
committed
fix: failed to fetch
1 parent b16c47e commit 481c80c

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

webapp/_webapp/src/background.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ export type HandlerAny = Handler<any, any>;
2929
export const getCookiesHandler: Handler<void, { session?: string; gclb?: string }> = {
3030
name: HANDLER_NAMES.GET_COOKIES,
3131
handler: async (_, sendResponse) => {
32-
const cookies = await getAllCookies("overleaf_session2", "https://www.overleaf.com");
33-
const gclb = await getAllCookies("GCLB", "https://www.overleaf.com");
32+
const currentDomain = window.location.hostname;
33+
const cookies = await getAllCookies("overleaf_session2", "https://" + currentDomain);
34+
const gclb = await getAllCookies("GCLB", "https://" + currentDomain);
3435
sendResponse({ session: cookies[0]?.value, gclb: gclb[0]?.value });
3536
},
3637
};

webapp/_webapp/src/libs/overleaf-socket.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ async function opGetAllThreads(
155155
csrfToken: string,
156156
projectId: string,
157157
): Promise<Map<string, OverleafThread>> {
158-
const res = await fetch(`https://www.overleaf.com/project/${projectId}/threads`, {
158+
const currentDomain = window.location.hostname;
159+
const res = await fetch(`https://${currentDomain}/project/${projectId}/threads`, {
159160
headers: {
160161
Accept: "application/json",
161162
"Content-Type": "application/json",
@@ -192,7 +193,8 @@ export async function postCommentToThread(
192193
projectId: string,
193194
headers: HeadersInit,
194195
): Promise<void> {
195-
const threadUrl = `https://www.overleaf.com/project/${projectId}/thread/${threadId}/messages`;
196+
const currentDomain = window.location.hostname;
197+
const threadUrl = `https://${currentDomain}/project/${projectId}/thread/${threadId}/messages`;
196198
// console.log("Posting comment to thread:", threadUrl, comment);
197199

198200
if (!comment || comment.length === 0) {
@@ -225,7 +227,8 @@ export async function wsConnect(
225227
// if (import.meta.env.DEV) {
226228
// throw new Error("Development mode is not supported for wsConnect");
227229
// }
228-
const baseUrl = import.meta.env.DEV ? "http://localhost:3000" : "https://www.overleaf.com";
230+
const currentDomain = window.location.hostname;
231+
const baseUrl = import.meta.env.DEV ? "http://localhost:3000" : "https://" + currentDomain;
229232
const res = await fetch(`${baseUrl}/socket.io/1/?projectId=${projectId}&t=${Date.now()}`, {
230233
headers: {
231234
Accept: "application/json",
@@ -239,13 +242,13 @@ export async function wsConnect(
239242
throw new Error(`HTTP error when connecting ws: ${res.status}`);
240243
}
241244

242-
const wsUrl = import.meta.env.DEV ? "ws://localhost:3000" : "wss://www.overleaf.com";
245+
const wsUrl = import.meta.env.DEV ? "ws://localhost:3000" : "wss://" + currentDomain;
243246
const data = await res.text();
244247
const sessionId = data.split(":")[0];
245-
248+
246249
// Set cookies for WebSocket connection
247-
document.cookie = `overleaf_session2=${overleafAuth.cookieOverleafSession2}; path=/; domain=${import.meta.env.DEV ? "localhost" : "www.overleaf.com"}`;
248-
document.cookie = `GCLB=${overleafAuth.cookieGCLB}; path=/; domain=${import.meta.env.DEV ? "localhost" : "www.overleaf.com"}`;
250+
document.cookie = `overleaf_session2=${overleafAuth.cookieOverleafSession2}; path=/; domain=${import.meta.env.DEV ? "localhost" : currentDomain}`;
251+
document.cookie = `GCLB=${overleafAuth.cookieGCLB}; path=/; domain=${import.meta.env.DEV ? "localhost" : currentDomain}`;
249252

250253
return new WebSocket(`${wsUrl}/socket.io/1/websocket/${sessionId}?projectId=${projectId}`);
251254
}

0 commit comments

Comments
 (0)