Commit df76207
authored
[v2]: handle target closed errors on popups (#1710)
# why
- some popups close so quickly that Stagehand tries to attach a CDP
session after the target is already gone, which produces unhandled
`Target.attachToTarget` / `newCDPSession` errors
- in the case of fast‑closing popups during auto‑init, we want to treat
“target gone” as a benign race instead of surfacing as failures
# what changed
- added shared “target gone” helpers in `lib/utils.ts`
- guarded CDP session creation to throw a targeted error when the
page/frame is already closed or detached
- swallowed that targeted error during page initialization and frame
listener attach only when the target is closed or the error indicates
the target is gone, so other CDP failures still surface
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Handle rapidly opening/closing popups by detecting “target gone”
scenarios and preventing CDP session attach errors. This reduces
flakiness during auto-init and keeps fast-closing popups from surfacing
as failures.
- **Bug Fixes**
- Added StagehandTargetClosedError and utils to detect closed/detached
targets and CDP “target gone” errors.
- Guarded CDP session creation and frame listener attach; swallow only
“target closed” errors during init.
- Removed cached CDP clients when targets are gone and skipped work on
already-closed pages/frames.
<sup>Written for commit 6143b9c.
Summary will update on new commits. <a
href="https://cubic.dev/pr/browserbase/stagehand/pull/1710">Review in
cubic</a></sup>
<!-- End of auto-generated description by cubic. -->1 parent 60eef53 commit df76207
File tree
5 files changed
+95
-5
lines changed- .changeset
- lib
- types
5 files changed
+95
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
124 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
125 | 143 | | |
126 | 144 | | |
127 | | - | |
| 145 | + | |
128 | 146 | | |
129 | 147 | | |
130 | 148 | | |
| |||
179 | 197 | | |
180 | 198 | | |
181 | 199 | | |
| 200 | + | |
182 | 201 | | |
183 | 202 | | |
184 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
185 | 215 | | |
186 | 216 | | |
187 | 217 | | |
| |||
191 | 221 | | |
192 | 222 | | |
193 | 223 | | |
194 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
195 | 232 | | |
196 | 233 | | |
197 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
1049 | 1051 | | |
1050 | 1052 | | |
1051 | 1053 | | |
1052 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1053 | 1065 | | |
1054 | 1066 | | |
1055 | 1067 | | |
1056 | 1068 | | |
1057 | 1069 | | |
1058 | 1070 | | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
1059 | 1074 | | |
1060 | 1075 | | |
1061 | 1076 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
92 | 107 | | |
93 | 108 | | |
94 | 109 | | |
| |||
0 commit comments