@probolabs/playwright 0.4.7 → 0.4.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.
@@ -0,0 +1,63 @@
1
+ import { readFileSync } from 'fs';
2
+ import { join } from 'path';
3
+
4
+ const ElementTag = {
5
+ CLICKABLE: "CLICKABLE", // button, link, toggle switch, checkbox, radio, dropdowns, clickable divs
6
+ FILLABLE: "FILLABLE", // input, textarea content_editable, date picker??
7
+ SELECTABLE: "SELECTABLE", // select
8
+ NON_INTERACTIVE_ELEMENT: 'NON_INTERACTIVE_ELEMENT',
9
+ };
10
+
11
+ // Import ElementTag from constants
12
+ // Read the UMD bundle at build time
13
+ const highlighterCode = readFileSync(join(__dirname, '../../probo-highlighter/dist/probolabs.umd.js'), 'utf8');
14
+ class Probo {
15
+ constructor(token, apiUrl) {
16
+ this.token = token;
17
+ this.apiUrl = apiUrl;
18
+ console.log('Probo constructor', this.token, this.apiUrl);
19
+ }
20
+ setupConsoleLogs(page) {
21
+ {
22
+ page.on('console', msg => {
23
+ const type = msg.type();
24
+ const text = msg.text();
25
+ console.log(`BROWSER CONSOLE [${type}]: ${text}`);
26
+ });
27
+ }
28
+ }
29
+ async ensureHighlighterScript(page) {
30
+ this.setupConsoleLogs(page);
31
+ const scriptExists = await page.evaluate(`typeof window.ProboLabs?.highlight?.execute === 'function'`);
32
+ if (!scriptExists) {
33
+ console.log('DEBUG: Injecting highlighter script...');
34
+ await page.evaluate(highlighterCode);
35
+ // Verify the script was injected correctly
36
+ const verified = await page.evaluate(`
37
+ console.log('ProboLabs global:', window.ProboLabs);
38
+ typeof window.ProboLabs?.highlight?.execute === 'function'
39
+ `);
40
+ console.log('DEBUG: Script injection verified:', verified);
41
+ }
42
+ }
43
+ async highlightElements(page, elementTag) {
44
+ console.log('highlightElements called with:', elementTag);
45
+ await this.ensureHighlighterScript(page);
46
+ // Execute the highlight function and await its result
47
+ const result = await page.evaluate(async (tag) => {
48
+ var _a, _b;
49
+ console.log('Browser: Starting highlight execution with tag:', tag);
50
+ if (!((_b = (_a = window.ProboLabs) === null || _a === void 0 ? void 0 : _a.highlight) === null || _b === void 0 ? void 0 : _b.execute)) {
51
+ console.error('Browser: ProboLabs.highlight.execute is not available!');
52
+ return null;
53
+ }
54
+ const elements = await window.ProboLabs.highlight.execute([tag]);
55
+ console.log('Browser: Found elements:', elements);
56
+ return elements;
57
+ }, elementTag);
58
+ console.log('Highlight result:', result);
59
+ return result;
60
+ }
61
+ }
62
+
63
+ export { ElementTag, Probo };