@empiricalrun/playwright-utils 0.6.0 → 0.6.1
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mouse-pointer.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/mouse-pointer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"mouse-pointer.d.ts","sourceRoot":"","sources":["../../../src/test/scripts/mouse-pointer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,QAoGpD"}
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addMousePointerHighlighter = void 0;
|
|
4
4
|
function addMousePointerHighlighter(page) {
|
|
5
5
|
page.on("load", async () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
try {
|
|
7
|
+
await page?.evaluate(() => {
|
|
8
|
+
const box = document.createElement("div");
|
|
9
|
+
box.classList.add("empirical-mouse-pointer");
|
|
10
|
+
const styleElement = document.createElement("style");
|
|
11
|
+
styleElement.textContent = `
|
|
11
12
|
.empirical-mouse-pointer {
|
|
12
13
|
pointer-events: none;
|
|
13
14
|
position: absolute;
|
|
@@ -53,28 +54,32 @@ function addMousePointerHighlighter(page) {
|
|
|
53
54
|
outline: 2px dashed #FF000D !important;
|
|
54
55
|
}
|
|
55
56
|
`;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
document.head.appendChild(styleElement);
|
|
58
|
+
document.body.appendChild(box);
|
|
59
|
+
document.addEventListener("mousemove", (event) => {
|
|
60
|
+
box.style.left = `${event.pageX}px`;
|
|
61
|
+
box.style.top = `${event.pageY}px`;
|
|
62
|
+
updateButtons(event.buttons);
|
|
63
|
+
}, true);
|
|
64
|
+
document.addEventListener("mousedown", (event) => {
|
|
65
|
+
updateButtons(event.buttons);
|
|
66
|
+
box.classList.add(`button-${event.button + 1}`);
|
|
67
|
+
}, true);
|
|
68
|
+
document.addEventListener("mouseup", (event) => {
|
|
69
|
+
updateButtons(event.buttons);
|
|
70
|
+
box.classList.remove(`button-${event.button + 1}`);
|
|
71
|
+
}, true);
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
function updateButtons(buttons) {
|
|
74
|
+
for (let i = 0; i < 5; i++) {
|
|
75
|
+
box.classList.toggle(`button-${i + 1}`, (buttons / Math.pow(2, i)) % 2 >= 1);
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
console.log(`Error adding mouse pointer highlighter`, e);
|
|
82
|
+
}
|
|
78
83
|
});
|
|
79
84
|
}
|
|
80
85
|
exports.addMousePointerHighlighter = addMousePointerHighlighter;
|