@ddwang/magnitude-core 0.3.1-ddwang.8 → 0.3.1-ddwang.9

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.
@@ -149,7 +149,7 @@ export const switchTabAction = createAction({
149
149
  });
150
150
  export const newTabAction = createAction({
151
151
  name: 'browser:tab:new',
152
- description: "Open and switch to a new tab",
152
+ description: "Open and switch to a new blank tab. Use browser:nav to navigate it to a URL.",
153
153
  schema: z.object({}),
154
154
  resolver: async ({ agent }) => {
155
155
  const webConnector = agent.require(BrowserConnector);
package/dist/index.cjs CHANGED
@@ -5506,6 +5506,7 @@ class TabManager {
5506
5506
  activePage;
5507
5507
  options;
5508
5508
  pollInterval;
5509
+ lastExplicitSwitch = 0;
5509
5510
  events;
5510
5511
  constructor(context, options = {}) {
5511
5512
  this.context = context;
@@ -5651,7 +5652,7 @@ class TabManager {
5651
5652
  } catch (e) {
5652
5653
  }
5653
5654
  }
5654
- if (mostRecentPage && mostRecentPage !== this.activePage && mostRecentTime > Date.now() - 1e3) {
5655
+ if (mostRecentPage && mostRecentPage !== this.activePage && mostRecentTime > this.lastExplicitSwitch && mostRecentTime > Date.now() - 1e3) {
5655
5656
  logger.trace(`Activity detected on ${mostRecentPage.url()}, switching...`);
5656
5657
  this.setActivePage(mostRecentPage);
5657
5658
  }
@@ -5678,6 +5679,8 @@ class TabManager {
5678
5679
  const page = pages[index];
5679
5680
  logger.debug(`Switching to tab ${index} (${page.url()})`);
5680
5681
  await page.bringToFront();
5682
+ checkOperation();
5683
+ this.lastExplicitSwitch = Date.now();
5681
5684
  this.setActivePage(page);
5682
5685
  }
5683
5686
  getActivePage() {
@@ -6563,8 +6566,8 @@ class WebHarness {
6563
6566
  }
6564
6567
  async newTab() {
6565
6568
  checkOperation();
6566
- await this.context.newPage();
6567
- await this.navigate("https://google.com");
6569
+ const page = await this.context.newPage();
6570
+ await this.switchTab({ index: this.context.pages().indexOf(page) });
6568
6571
  }
6569
6572
  async navigate(url) {
6570
6573
  checkOperation();
@@ -6779,7 +6782,7 @@ const switchTabAction = createAction({
6779
6782
  });
6780
6783
  const newTabAction = createAction({
6781
6784
  name: "browser:tab:new",
6782
- description: "Open and switch to a new tab",
6785
+ description: "Open and switch to a new blank tab. Use browser:nav to navigate it to a URL.",
6783
6786
  schema: z.z.object({}),
6784
6787
  resolver: async ({ agent }) => {
6785
6788
  const webConnector = agent.require(BrowserConnector);
package/dist/index.mjs CHANGED
@@ -5483,6 +5483,7 @@ class TabManager {
5483
5483
  activePage;
5484
5484
  options;
5485
5485
  pollInterval;
5486
+ lastExplicitSwitch = 0;
5486
5487
  events;
5487
5488
  constructor(context, options = {}) {
5488
5489
  this.context = context;
@@ -5628,7 +5629,7 @@ class TabManager {
5628
5629
  } catch (e) {
5629
5630
  }
5630
5631
  }
5631
- if (mostRecentPage && mostRecentPage !== this.activePage && mostRecentTime > Date.now() - 1e3) {
5632
+ if (mostRecentPage && mostRecentPage !== this.activePage && mostRecentTime > this.lastExplicitSwitch && mostRecentTime > Date.now() - 1e3) {
5632
5633
  logger.trace(`Activity detected on ${mostRecentPage.url()}, switching...`);
5633
5634
  this.setActivePage(mostRecentPage);
5634
5635
  }
@@ -5655,6 +5656,8 @@ class TabManager {
5655
5656
  const page = pages[index];
5656
5657
  logger.debug(`Switching to tab ${index} (${page.url()})`);
5657
5658
  await page.bringToFront();
5659
+ checkOperation();
5660
+ this.lastExplicitSwitch = Date.now();
5658
5661
  this.setActivePage(page);
5659
5662
  }
5660
5663
  getActivePage() {
@@ -6540,8 +6543,8 @@ class WebHarness {
6540
6543
  }
6541
6544
  async newTab() {
6542
6545
  checkOperation();
6543
- await this.context.newPage();
6544
- await this.navigate("https://google.com");
6546
+ const page = await this.context.newPage();
6547
+ await this.switchTab({ index: this.context.pages().indexOf(page) });
6545
6548
  }
6546
6549
  async navigate(url) {
6547
6550
  checkOperation();
@@ -6756,7 +6759,7 @@ const switchTabAction = createAction({
6756
6759
  });
6757
6760
  const newTabAction = createAction({
6758
6761
  name: "browser:tab:new",
6759
- description: "Open and switch to a new tab",
6762
+ description: "Open and switch to a new blank tab. Use browser:nav to navigate it to a URL.",
6760
6763
  schema: z.object({}),
6761
6764
  resolver: async ({ agent }) => {
6762
6765
  const webConnector = agent.require(BrowserConnector);
@@ -387,9 +387,8 @@ export class WebHarness {
387
387
  }
388
388
  async newTab() {
389
389
  checkOperation();
390
- await this.context.newPage();
391
- // Reasonable default and less confusing than white about:blank page
392
- await this.navigate("https://google.com");
390
+ const page = await this.context.newPage();
391
+ await this.switchTab({ index: this.context.pages().indexOf(page) });
393
392
  }
394
393
  async navigate(url) {
395
394
  checkOperation();
@@ -18,6 +18,7 @@ export declare class TabManager {
18
18
  private activePage;
19
19
  private options;
20
20
  private pollInterval?;
21
+ private lastExplicitSwitch;
21
22
  readonly events: EventEmitter<TabEvents>;
22
23
  constructor(context: BrowserContext, options?: TabManagerOptions);
23
24
  initialize(): Promise<void>;
package/dist/web/tabs.js CHANGED
@@ -2,11 +2,13 @@
2
2
  import logger from "@/logger";
3
3
  import EventEmitter from "eventemitter3";
4
4
  import { retryOnErrorIsSuccess } from "@/common";
5
+ import { checkOperation } from "@/common/operation";
5
6
  export class TabManager {
6
7
  context;
7
8
  activePage;
8
9
  options;
9
10
  pollInterval;
11
+ lastExplicitSwitch = 0;
10
12
  events;
11
13
  constructor(context, options = {}) {
12
14
  this.context = context;
@@ -193,6 +195,7 @@ export class TabManager {
193
195
  // Switch to the most recently active page if it's different and activity is recent
194
196
  if (mostRecentPage &&
195
197
  mostRecentPage !== this.activePage &&
198
+ mostRecentTime > this.lastExplicitSwitch &&
196
199
  mostRecentTime > Date.now() - 1000) { // Activity within last second
197
200
  logger.trace(`Activity detected on ${mostRecentPage.url()}, switching...`);
198
201
  this.setActivePage(mostRecentPage);
@@ -223,6 +226,9 @@ export class TabManager {
223
226
  const page = pages[index];
224
227
  logger.debug(`Switching to tab ${index} (${page.url()})`);
225
228
  await page.bringToFront();
229
+ checkOperation();
230
+ // Activity sampled before this switch must not undo the explicit selection.
231
+ this.lastExplicitSwitch = Date.now();
226
232
  this.setActivePage(page);
227
233
  }
228
234
  getActivePage() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddwang/magnitude-core",
3
- "version": "0.3.1-ddwang.8",
3
+ "version": "0.3.1-ddwang.9",
4
4
  "description": "Magnitude e2e testing agent",
5
5
  "publishConfig": {
6
6
  "access": "public"