Skip to content

Commit d2b12e7

Browse files
committed
fixing mouse cursor again
1 parent 2125374 commit d2b12e7

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

packages/action/dist/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41792,6 +41792,8 @@ function buildScriptGenerationPrompt(options) {
4179241792
- The script must be self-contained and immediately runnable
4179341793
- Total demo should be under ${options.maxDuration} seconds
4179441794
- Do NOT test correctness \u2014 demonstrate the feature. Show it working, not edge cases.
41795+
- Act as a real user: only interact through the UI using standard Playwright actions (navigate, click, type, hover). Never re-implement or simulate application features in the script.
41796+
- Do NOT inject code into the page via \`page.evaluate\`, \`page.addInitScript\`, or inline \`<script>\` / \`<style>\` tags. The recording infrastructure handles visual overlays \u2014 the script should not.
4179541797
- Always call \`await page.waitForLoadState('networkidle')\` after navigation
4179641798

4179741799
## Context
@@ -41906,6 +41908,12 @@ async function runScriptAndRecord(options) {
4190641908
try {
4190741909
const context2 = await createContext(browser, recording, outputDir);
4190841910
const page = await context2.newPage();
41911+
if (recording.showMouseClicks !== false) {
41912+
page.on("load", () => {
41913+
page.evaluate(buildMouseClickOverlayEvalScript()).catch(() => {
41914+
});
41915+
});
41916+
}
4190941917
await page.goto(baseUrl);
4191041918
await executeScript(script, page, baseUrl);
4191141919
const elapsed = (Date.now() - startTime) / 1e3;
@@ -41929,13 +41937,12 @@ async function createContext(browser, recording, outputDir) {
4192941937
viewport: recording.viewport,
4193041938
deviceScaleFactor: recording.deviceScaleFactor
4193141939
});
41932-
if (recording.showMouseClicks !== false) {
41933-
await context2.addInitScript(buildMouseClickOverlayScript());
41934-
}
4193541940
return context2;
4193641941
}
41937-
function buildMouseClickOverlayScript() {
41942+
function buildMouseClickOverlayEvalScript() {
4193841943
return `(() => {
41944+
if (document.querySelector('.gg-cursor')) return;
41945+
4193941946
const style = document.createElement('style');
4194041947
style.textContent = \`
4194141948
.gg-cursor {
@@ -41964,6 +41971,13 @@ function buildMouseClickOverlayScript() {
4196441971
cursor.className = 'gg-cursor';
4196541972
document.body.appendChild(cursor);
4196641973

41974+
const observer = new MutationObserver(() => {
41975+
if (!document.body.contains(cursor)) {
41976+
document.body.appendChild(cursor);
41977+
}
41978+
});
41979+
observer.observe(document.body, { childList: true, subtree: false });
41980+
4196741981
document.addEventListener('mousemove', (e) => {
4196841982
cursor.style.left = e.clientX + 'px';
4196941983
cursor.style.top = e.clientY + 'px';

0 commit comments

Comments
 (0)