Commit 91c846b
committed
fix(browser): clear stale Chrome singleton lock before launch
When an MCP client (or the host process) crashes or is killed without
cleanly shutting down the browser, Chrome's singleton lock files
(SingletonLock, SingletonSocket, SingletonCookie) persist in the user
data directory. On the next startup Chrome refuses to launch because it
believes another instance is already running, producing the error:
"The browser is already running for <userDataDir>."
This is particularly disruptive for MCP clients that manage the browser
lifecycle automatically — users have to manually find and delete the
lock files or restart their machine to recover.
This commit adds a `clearStaleSingletonLock()` helper that runs before
`puppeteer.launch()` when a persistent user data directory is in use.
It reads the PID encoded in the SingletonLock symlink (format:
`hostname-PID`), checks whether that process is still alive via
`process.kill(pid, 0)`, and removes the lock files only when the
process no longer exists. If the process is still running the lock is
left untouched and Chrome's own conflict detection handles it normally.1 parent 080bcf6 commit 91c846b
1 file changed
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
170 | 209 | | |
171 | 210 | | |
172 | 211 | | |
| |||
212 | 251 | | |
213 | 252 | | |
214 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
215 | 258 | | |
216 | 259 | | |
217 | 260 | | |
| |||
0 commit comments