cjc0013 commited on
Commit
978488a
·
verified ·
1 Parent(s): f5f3e27

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +162 -3
README.md CHANGED
@@ -1,3 +1,162 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - browser-extension
5
+ - firefox
6
+ - chatgpt
7
+ - performance
8
+ - memory
9
+ ---
10
+
11
+ # ChatGPT Traffic Gate (Firefox MV3) — AutoPilot v2.2 (Safer)
12
+
13
+ This repo is **not a dataset** in the normal HF sense. It’s a place to host a **Firefox MV3 extension** that tries to keep ChatGPT usable when you have **lots of tabs** and/or **very long conversations**.
14
+
15
+ ## What it does (plain version)
16
+
17
+ - **Blocks “load more history” pagination requests** by default (the big ones that spike RAM / lag / churn).
18
+ - If history pagination is allowed, it can **thin huge JSON responses** (keeps the latest chunk and the needed ancestors for ChatGPT’s conversation mapping).
19
+ - **Soft-caps the chat DOM** by trimming old conversation turns out of the page:
20
+ - visible tab: keep ~60 turns
21
+ - hidden tab: keep ~20 turns
22
+ - hidden for ~10 minutes: keep ~12 turns
23
+ - **Keeps the session warm** with low-overhead pings:
24
+ - **leader-only** pings from the active tab
25
+ - plus a low-frequency **background event-page ping** (single place, not per-tab)
26
+ - Adds a tiny **UI pill** so you can quickly toggle the gate or temporarily allow history.
27
+
28
+ This does **not** delete your chats on the server. It only changes what loads and what stays in the DOM.
29
+
30
+ ---
31
+
32
+ ## Repo contents
33
+
34
+ You get the extension **two ways**:
35
+
36
+ - `chat-traffic-gate-leader-softcap/` — unpacked extension folder
37
+ - `chat-traffic-gate-leader-softcap.zip` — the same thing, zipped
38
+
39
+ Inside the folder:
40
+
41
+ - `manifest.json` — MV3 manifest (Firefox)
42
+ - `background.js` — request gating + leader/follower role assignment + background alarm ping
43
+ - `content/early-shield.js` — briefly hides turns at page start, then unshields
44
+ - `content/net-guard.js` — patches `fetch` + XHR at `document_start` to block pagination and (when allowed) thin big JSON
45
+ - `content/dom-softcap.js` — trims old conversation turns out of the DOM (changes based on tab visibility)
46
+ - `content/keepalive.js` — leader-only keepalive pings + reconnect helper (reloads OFF by default)
47
+ - `content/autopilot.js` — visible-tab tuning (intent detection + adjusts keepalive/softcap if things look bad)
48
+ - `content/traffic-ui.js` — UI pill (“🚦 On/Off” + “Allow 10s”)
49
+
50
+ ---
51
+
52
+ ## Install (fast / lazy)
53
+
54
+ ### Option A — load unpacked folder (recommended)
55
+ 1. Download `chat-traffic-gate-leader-softcap.zip` from this repo and unzip it.
56
+ 2. In Firefox, open: `about:debugging#/runtime/this-firefox`
57
+ 3. Click **Load Temporary Add-on…**
58
+ 4. Select the **`manifest.json`** inside the unzipped folder.
59
+
60
+ Temporary addons disappear when Firefox restarts (that’s normal).
61
+
62
+ ### Option B — use the unpacked folder in the repo
63
+ Same process as above, but download the folder contents and point Firefox at `manifest.json`.
64
+
65
+ ---
66
+
67
+ ## How the “history gate” works
68
+
69
+ ### Background layer (webRequest)
70
+ `background.js` uses `webRequestBlocking` to cancel only **true pagination** requests:
71
+ - it looks for query params like `cursor`, `before`, `offset>0`, `page>1`, or backward direction markers
72
+ - it only applies to “history-like” endpoints
73
+ - it avoids blanket blocking (session and models endpoints are allow-listed)
74
+
75
+ ### Page layer (fetch/XHR patch)
76
+ `content/net-guard.js` runs at `document_start` and patches:
77
+ - `window.fetch`
78
+ - `XMLHttpRequest`
79
+
80
+ If a request is a paginated history load **and** you didn’t indicate intent:
81
+ - some list endpoints get a **safe empty page JSON** (soft-block)
82
+ - others get an AbortError / aborted XHR (hard-block)
83
+
84
+ ### Intent + temporary allow
85
+ The extension decides “intent” mostly from **scroll behavior**:
86
+ - near the top, or scrolling upward recently → intent = true
87
+ - otherwise intent = false
88
+
89
+ You can also force allow pagination for a short window:
90
+ - UI pill: **Allow 10s**
91
+ - programmatic: `__chatTrafficGate.allowForMs(10000)`
92
+
93
+ ---
94
+
95
+ ## JSON thinning (what it actually does)
96
+
97
+ Only when a request is a **paginated history request** (the same pagination detection as above), it may thin JSON:
98
+ - if `messages[]` is huge → keep the newest ~60
99
+ - if `items[]` is huge → keep the newest ~60
100
+ - if ChatGPT’s `mapping{}` is huge → keep the newest ~60 nodes **plus ancestors** (and keep `current_node` / `root` when present)
101
+
102
+ Goal: reduce payload size while keeping the mapping structurally coherent.
103
+
104
+ ---
105
+
106
+ ## DOM soft-cap (memory control)
107
+
108
+ The softcap script trims old turn nodes from the DOM using:
109
+
110
+ - selector: `[data-testid^="conversation-turn-"]`
111
+
112
+ It tries to keep the UI stable by:
113
+ - trimming in batches
114
+ - briefly hiding the container while trimming to reduce layout thrash
115
+ - unshielding the early CSS shield once the first trim completes
116
+
117
+ ---
118
+
119
+ ## Keepalive + reconnect behavior
120
+
121
+ ### Leader-only pings
122
+ Only the **active tab** is intended to be “leader” and run keepalive pings. Background assigns roles and tells tabs to switch.
123
+
124
+ ### Endpoints it tries
125
+ It probes a small set and sticks with the first one that works, e.g.:
126
+ - `/api/auth/session`
127
+ - `/backend-api/models`
128
+ - `/backend-api/conversations?offset=0&limit=1`
129
+ - `/favicon.ico`
130
+ - `/`
131
+
132
+ ### Reconnect helper
133
+ It watches the DOM for text like “reconnecting / disconnected / network error” and tries:
134
+ - click buttons with text like “Retry / Reconnect / Try again”
135
+ - **reload is OFF by default** (AutoPilot may enable it temporarily if disconnects are bad)
136
+
137
+ ---
138
+
139
+ ## UI controls
140
+
141
+ A small pill appears on the page:
142
+
143
+ - **🚦 On / Off**: toggles history gating
144
+ - **Allow 10s**: allows pagination for 10 seconds in that tab
145
+
146
+ ---
147
+
148
+ ## Dev / power-user globals
149
+
150
+ These are intentionally exposed by the scripts:
151
+
152
+ ```js
153
+ __chatTrafficGate.setEnabled(true|false)
154
+ __chatTrafficGate.setIntent(true|false)
155
+ __chatTrafficGate.allowForMs(10000)
156
+
157
+ __chatSoftCap.setConfig({ enabled: true, keep: 60, keepHidden: 20, keepDeepHidden: 12 })
158
+
159
+ __chatKeepalive.setMinutes(4)
160
+ __chatKeepalive.setAutoReconnect(true)
161
+ __chatKeepalive.setAllowReloads(false)
162
+ __chatKeepalive.reconnectNow()