@empiricalrun/playwright-utils 0.38.3 → 0.38.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @empiricalrun/playwright-utils
2
2
 
3
+ ## 0.38.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 86a9e1d: feat: improvements to overlay dismissal telemetry
8
+
9
+ ## 0.38.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 48126ea: feat: cost tracking for overlay dismissals
14
+ - Updated dependencies [48126ea]
15
+ - @empiricalrun/test-gen@0.79.1
16
+ - @empiricalrun/llm@0.25.2
17
+
3
18
  ## 0.38.3
4
19
 
5
20
  ### Patch Changes
@@ -1,8 +1,19 @@
1
1
  import { TelemetryEvent } from "@empiricalrun/shared-types/telemetry";
2
2
  export declare function trackEvent(event: TelemetryEvent): Promise<void>;
3
3
  export declare function trackOverlayDismissed(opts: {
4
- overlayDescription: string;
5
- cacheHit: boolean;
4
+ original: string | undefined;
5
+ description: string;
6
+ text: string | undefined;
7
+ cache: boolean;
6
8
  success: boolean;
9
+ testName?: string;
10
+ tokens?: {
11
+ input: number;
12
+ output: number;
13
+ };
14
+ cost?: {
15
+ input: number;
16
+ output: number;
17
+ };
7
18
  }): void;
8
19
  //# sourceMappingURL=telemetry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAKtE,wBAAsB,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBrE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,IAAI,CAaP"}
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAKtE,wBAAsB,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBrE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,GAAG,IAAI,CAoBP"}
package/dist/telemetry.js CHANGED
@@ -4,6 +4,7 @@ exports.trackEvent = trackEvent;
4
4
  exports.trackOverlayDismissed = trackOverlayDismissed;
5
5
  const TELEMETRY_WORKER_URL = "https://telemetry-worker.empirical-run.workers.dev";
6
6
  async function trackEvent(event) {
7
+ console.log("----", event);
7
8
  const apiKey = process.env.EMPIRICAL_TELEMETRY_API_KEY;
8
9
  if (!apiKey) {
9
10
  return;
@@ -31,11 +32,18 @@ function trackOverlayDismissed(opts) {
31
32
  name: "overlay.dismissed",
32
33
  properties: {
33
34
  environment,
34
- overlay_description: opts.overlayDescription,
35
- cache_hit: opts.cacheHit,
35
+ overlay_description: opts.description,
36
+ overlay_text: opts.text ?? "",
37
+ original_locator: opts.original ?? "",
38
+ cache_hit: opts.cache,
36
39
  success: opts.success,
37
40
  project_name: process.env.PROJECT_NAME ?? "",
38
41
  test_run_id: process.env.TEST_RUN_GITHUB_ACTION_ID ?? "",
42
+ test_name: opts.testName ?? "",
43
+ tokens_input: opts.tokens?.input ?? 0,
44
+ tokens_output: opts.tokens?.output ?? 0,
45
+ cost_input: opts.cost?.input ?? 0,
46
+ cost_output: opts.cost?.output ?? 0,
39
47
  },
40
48
  });
41
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAO9C,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,qBAAa,mBAAmB;IAOlB,OAAO,CAAC,QAAQ,CAAC,IAAI;IANjC,OAAO,CAAC,iBAAiB,CAIhB;gBAEoB,IAAI,EAAE,IAAI;IAEjC,WAAW;IAMX,GAAG,CACP,aAAa,EAAE,GAAG,EAClB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;YA2CF,QAAQ;CAwCvB;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GACnB,cAAc,GAAG,SAAS,CAiC5B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAK9C,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,WAKhE;AAED,qBAAa,mBAAmB;IAOlB,OAAO,CAAC,QAAQ,CAAC,IAAI;IANjC,OAAO,CAAC,iBAAiB,CAIhB;gBAEoB,IAAI,EAAE,IAAI;IAEjC,WAAW;IAMX,GAAG,CACP,aAAa,EAAE,GAAG,EAClB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;YAqDF,QAAQ;CA6BvB;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,GACnB,cAAc,GAAG,SAAS,CAiC5B"}
@@ -9,7 +9,6 @@ const cache_1 = require("./cache");
9
9
  const prompt_1 = require("./prompt");
10
10
  const utils_1 = require("./utils");
11
11
  const ERROR_SUBSTRING_INTERCEPTION = "intercepts pointer events";
12
- const PREFERRED_AGENT = "openai-cua";
13
12
  function isErrorSupported(errorMessage) {
14
13
  if (!errorMessage) {
15
14
  return false;
@@ -36,9 +35,16 @@ class OverlayDismissAgent {
36
35
  // Ignoring this error
37
36
  }
38
37
  const description = (0, utils_1.overlayDescription)(element) ?? "unknown";
38
+ const testName = testFn.info().title;
39
39
  reporter(`Attempting to auto-dismiss overlay: ${description}`);
40
+ const text = await (0, utils_1.textContent)(this.page, element);
41
+ const eventProps = {
42
+ description,
43
+ text,
44
+ testName,
45
+ original: originalFailingLocator(originalError.message),
46
+ };
40
47
  try {
41
- const text = await (0, utils_1.textContent)(this.page, element);
42
48
  const { success } = await (0, cache_1.executeFromCache)({
43
49
  page: this.page,
44
50
  dom: element?.interceptor,
@@ -46,24 +52,26 @@ class OverlayDismissAgent {
46
52
  });
47
53
  if (success) {
48
54
  (0, telemetry_1.trackOverlayDismissed)({
49
- overlayDescription: description,
50
- cacheHit: true,
55
+ ...eventProps,
56
+ cache: true,
51
57
  success: true,
52
58
  });
53
59
  return;
54
60
  }
55
- await this.runAgent(element, text, testFn);
61
+ const usage = await this.runAgent(element, text, testFn);
56
62
  (0, telemetry_1.trackOverlayDismissed)({
57
- overlayDescription: description,
58
- cacheHit: false,
63
+ ...eventProps,
64
+ cache: false,
59
65
  success: true,
66
+ tokens: usage.tokens,
67
+ cost: usage.cost,
60
68
  });
61
69
  }
62
70
  catch (agentError) {
63
71
  reporter(`Error during overlay dismissal agent execution: ${agentError.toString()}`);
64
72
  (0, telemetry_1.trackOverlayDismissed)({
65
- overlayDescription: description,
66
- cacheHit: false,
73
+ ...eventProps,
74
+ cache: false,
67
75
  success: false,
68
76
  });
69
77
  throw originalError;
@@ -72,39 +80,24 @@ class OverlayDismissAgent {
72
80
  async runAgent(element, text, testFn) {
73
81
  const task = await (0, prompt_1.getTask)(this.page, element, text);
74
82
  const trace = (0, utils_1.traceThis)(task, testFn);
75
- if (PREFERRED_AGENT === "inhouse-master") {
76
- const result = await (0, run_1.createTestUsingMasterAgent)({
77
- task,
78
- page: this.page,
79
- options: {
80
- useActionSpecificAnnotations: true,
81
- },
82
- });
83
- this.cachingCandidates.push({
84
- dom: element?.interceptor,
85
- text,
86
- code: result.code,
87
- });
88
- }
89
- else if (PREFERRED_AGENT === "openai-cua") {
90
- const result = await (0, run_1.createTestUsingComputerUseAgent)({
91
- page: this.page,
92
- task,
93
- trace,
94
- // We don't want to use page.pause approach here because
95
- // overlay dismissal can kick in during a browser agent tool call
96
- // and we need app to be able to use page.pause for agent actions.
97
- // Currently, page.pause does not cleanup properly, causing it to work
98
- // only once in a particular test run.
99
- // Ran into this here: https://dash.empirical.run/quizizz-tests/sessions/2825
100
- prefersElementFromPointCodegen: true,
101
- });
102
- this.cachingCandidates.push({
103
- dom: element?.interceptor,
104
- text,
105
- code: result.code,
106
- });
107
- }
83
+ const result = await (0, run_1.createTestUsingComputerUseAgent)({
84
+ page: this.page,
85
+ task,
86
+ trace,
87
+ // We don't want to use page.pause approach here because
88
+ // overlay dismissal can kick in during a browser agent tool call
89
+ // and we need app to be able to use page.pause for agent actions.
90
+ // Currently, page.pause does not cleanup properly, causing it to work
91
+ // only once in a particular test run.
92
+ // Ran into this here: https://dash.empirical.run/quizizz-tests/sessions/2825
93
+ prefersElementFromPointCodegen: true,
94
+ });
95
+ this.cachingCandidates.push({
96
+ dom: element?.interceptor,
97
+ text,
98
+ code: result.code,
99
+ });
100
+ return result.usage;
108
101
  }
109
102
  }
110
103
  exports.OverlayDismissAgent = OverlayDismissAgent;
@@ -144,6 +137,15 @@ function extractInterceptingElement(errorMessage) {
144
137
  };
145
138
  }
146
139
  }
140
+ function originalFailingLocator(errorMessage) {
141
+ try {
142
+ const p = removeAnsiCodes(errorMessage).split("waiting for ")[1];
143
+ return p?.split("\n")[0];
144
+ }
145
+ catch {
146
+ return "";
147
+ }
148
+ }
147
149
  function removeAnsiCodes(str) {
148
150
  const ansiRegex = new RegExp(String.raw `\u001b\[[0-9;]*m`, "g");
149
151
  return str.replace(ansiRegex, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/playwright-utils",
3
- "version": "0.38.3",
3
+ "version": "0.38.5",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "author": "Empirical Team <hey@empirical.run>",
24
24
  "devDependencies": {
25
- "@playwright/test": "1.53.2",
25
+ "@playwright/test": "1.57.0",
26
26
  "@types/async-retry": "^1.4.8",
27
27
  "@types/authenticator": "^1.1.4",
28
28
  "@types/babel__code-frame": "^7.0.6",
@@ -30,7 +30,7 @@
30
30
  "@types/node": "^20.14.9",
31
31
  "@types/serve-handler": "^6.1.4",
32
32
  "@types/pg": "^8.11.6",
33
- "playwright-core": "1.53.2",
33
+ "playwright-core": "1.57.0",
34
34
  "serve-handler": "^6.1.6",
35
35
  "@empiricalrun/shared-types": "0.12.0"
36
36
  },
@@ -42,9 +42,9 @@
42
42
  "console-log-level": "^1.4.1",
43
43
  "puppeteer-extra-plugin-recaptcha": "^3.6.8",
44
44
  "rimraf": "^6.0.1",
45
- "@empiricalrun/llm": "^0.25.1",
46
- "@empiricalrun/r2-uploader": "^0.9.0",
47
- "@empiricalrun/test-gen": "^0.79.0"
45
+ "@empiricalrun/llm": "^0.25.2",
46
+ "@empiricalrun/test-gen": "^0.79.1",
47
+ "@empiricalrun/r2-uploader": "^0.9.0"
48
48
  },
49
49
  "scripts": {
50
50
  "dev": "tsc --build --watch",