Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion maxun-core/src/interpret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ export default class Interpreter extends EventEmitter {
try {
await executeAction(invokee, methodName, step.args);
} catch (error) {
await executeAction(invokee, methodName, [step.args[0], { force: true }]);
try{
await executeAction(invokee, methodName, [step.args[0], { force: true }]);
} catch (error) {
continue
}
Comment on lines +509 to +513
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve error handling for click actions

While the attempt to handle click failures is good, the current implementation has some issues:

  1. Silent failure: The error is caught but not logged, making it difficult to debug issues.
  2. Potentially dangerous: Force clicking without checking element state could lead to unintended interactions.
  3. Inconsistent indentation in the try-catch block.

Consider this improved implementation:

            try {
              await executeAction(invokee, methodName, step.args);
            } catch (error) {
-              try{
-                await executeAction(invokee, methodName, [step.args[0], { force: true }]);
-              } catch (error) {
-                continue
-              }
+              try {
+                // Check if element exists but is not visible
+                const selector = step.args[0];
+                const isPresent = await page.$(selector);
+                if (!isPresent) {
+                  this.log(`Element not found: ${selector}`, Level.ERROR);
+                  continue;
+                }
+                const isVisible = await page.isVisible(selector);
+                if (!isVisible) {
+                  this.log(`Element not visible: ${selector}`, Level.WARN);
+                }
+                await executeAction(invokee, methodName, [selector, { force: true }]);
+              } catch (error) {
+                this.log(`Click action failed: ${error.message}`, Level.ERROR);
+                continue;
+              }
            }

Committable suggestion skipped: line range outside the PR's diff.

}
} else {
await executeAction(invokee, methodName, step.args);
Expand Down