browse 0.8.4-alpha-cffcc91 → 0.8.4-alpha-2441cd4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -156,19 +156,19 @@ export class DriverSessionManager {
|
|
|
156
156
|
if (!page) {
|
|
157
157
|
throw new Error(`Target ${target.targetId} was not found in the attached browser.`);
|
|
158
158
|
}
|
|
159
|
-
this.
|
|
159
|
+
this.activateIfNeeded(page);
|
|
160
160
|
this.selectedTargetId = page.targetId();
|
|
161
161
|
return page;
|
|
162
162
|
}
|
|
163
163
|
const existingPage = this.activePageIfPresent() ?? this.context.pages()[0];
|
|
164
164
|
if (existingPage) {
|
|
165
|
-
this.
|
|
165
|
+
this.activateIfNeeded(existingPage);
|
|
166
166
|
this.selectedTargetId = existingPage.targetId();
|
|
167
167
|
return existingPage;
|
|
168
168
|
}
|
|
169
169
|
if (options.createIfMissing) {
|
|
170
170
|
const page = await this.context.newPage();
|
|
171
|
-
this.
|
|
171
|
+
this.activateIfNeeded(page);
|
|
172
172
|
this.selectedTargetId = page.targetId();
|
|
173
173
|
return page;
|
|
174
174
|
}
|
|
@@ -182,6 +182,21 @@ export class DriverSessionManager {
|
|
|
182
182
|
return undefined;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Mark `page` active only when it isn't already the active page.
|
|
187
|
+
*
|
|
188
|
+
* `setActivePage` ends in a CDP `Target.activateTarget`, which on macOS
|
|
189
|
+
* raises the whole Chrome app to the OS foreground and steals keyboard focus.
|
|
190
|
+
* The daemon resolves the active page on every subcommand, so calling this
|
|
191
|
+
* unconditionally yanks focus away from the user's editor/terminal on each
|
|
192
|
+
* command in headed local mode. Skipping the redundant re-activation keeps a
|
|
193
|
+
* headed session usable alongside a coding agent.
|
|
194
|
+
*/
|
|
195
|
+
activateIfNeeded(page) {
|
|
196
|
+
if (page !== this.activePageIfPresent()) {
|
|
197
|
+
this.context?.setActivePage(page);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
185
200
|
async ensureInitialized() {
|
|
186
201
|
if (this.stagehand && this.context)
|
|
187
202
|
return;
|