Skip to content

Commit 1cd6d1f

Browse files
authored
fix(page-script): intercept only conversation endpoints (#16)
1 parent 65f302b commit 1cd6d1f

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

extension/src/page/page-script.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,19 @@ function isConversationRequest(method: string, url: URL): boolean {
186186
return false;
187187
}
188188

189-
// Only /backend-api/ endpoints
190-
if (!url.pathname.startsWith('/backend-api/')) {
191-
return false;
192-
}
193-
194-
return true;
189+
// Only endpoints that return the conversation tree we can trim.
190+
// ChatGPT performs many GET /backend-api/* requests on load (/me, /models, /settings, etc.).
191+
// Intercepting those adds unnecessary overhead (clone/json) and config gating delay.
192+
//
193+
// Allowed:
194+
// - /backend-api/conversation/<id>
195+
// - /backend-api/shared_conversation/<id> (share links)
196+
//
197+
// Explicitly excluded by pattern (extra path segments):
198+
// - /backend-api/conversation/<id>/stream_status
199+
// - /backend-api/conversation/<id>/textdocs
200+
const path = url.pathname;
201+
return /^\/backend-api\/(conversation|shared_conversation)\/[^/]+\/?$/.test(path);
195202
}
196203

197204
/**

tests/unit/page-script.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ describe('isConversationRequest logic', () => {
8282
// Testing the logic that would be in isConversationRequest
8383
const isConversationRequest = (method: string, pathname: string): boolean => {
8484
if (method !== 'GET') return false;
85-
if (!pathname.startsWith('/backend-api/')) return false;
86-
return true;
85+
return /^\/backend-api\/(conversation|shared_conversation)\/[^/]+\/?$/.test(pathname);
8786
};
8887

89-
it('returns true for GET /backend-api/ requests', () => {
88+
it('returns true only for conversation endpoints', () => {
9089
expect(isConversationRequest('GET', '/backend-api/conversation/123')).toBe(true);
91-
expect(isConversationRequest('GET', '/backend-api/conversation')).toBe(true);
92-
expect(isConversationRequest('GET', '/backend-api/')).toBe(true);
90+
expect(isConversationRequest('GET', '/backend-api/conversation/123/')).toBe(true);
91+
expect(isConversationRequest('GET', '/backend-api/shared_conversation/abc-xyz')).toBe(true);
9392
});
9493

9594
it('returns false for non-GET methods', () => {
@@ -98,6 +97,16 @@ describe('isConversationRequest logic', () => {
9897
expect(isConversationRequest('DELETE', '/backend-api/conversation')).toBe(false);
9998
});
10099

100+
it('returns false for non-conversation backend-api paths', () => {
101+
expect(isConversationRequest('GET', '/backend-api/')).toBe(false);
102+
expect(isConversationRequest('GET', '/backend-api/conversation')).toBe(false);
103+
expect(isConversationRequest('GET', '/backend-api/me')).toBe(false);
104+
expect(isConversationRequest('GET', '/backend-api/settings/user')).toBe(false);
105+
expect(isConversationRequest('GET', '/backend-api/models')).toBe(false);
106+
expect(isConversationRequest('GET', '/backend-api/conversation/123/stream_status')).toBe(false);
107+
expect(isConversationRequest('GET', '/backend-api/conversation/123/textdocs')).toBe(false);
108+
});
109+
101110
it('returns false for non-backend-api paths', () => {
102111
expect(isConversationRequest('GET', '/api/conversation')).toBe(false);
103112
expect(isConversationRequest('GET', '/conversation')).toBe(false);

0 commit comments

Comments
 (0)