Skip to content

Commit a1622f3

Browse files
committed
Try catching any errors
1 parent ac29ec6 commit a1622f3

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

tools/wptrunner/wptrunner/executors/platformaccessibility/executoraxapi.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@ def find_browser(name):
1818
:param name: The name of the browser.
1919
:return: AXUIElement or None.
2020
"""
21-
22-
ws = NSWorkspace.sharedWorkspace()
23-
regular_predicate = NSPredicate.predicateWithFormat_(
24-
f"activationPolicy == {NSApplicationActivationPolicyRegular}"
25-
)
26-
running_apps = ws.runningApplications().filteredArrayUsingPredicate_(
27-
regular_predicate
28-
)
29-
name_predicate = NSPredicate.predicateWithFormat_(
30-
f"localizedName contains[c] '{name}'"
31-
)
32-
filtered_apps = running_apps.filteredArrayUsingPredicate_(name_predicate)
33-
if filtered_apps.count() == 0:
34-
return None
35-
app = filtered_apps[0]
36-
pid = app.processIdentifier()
37-
if pid == -1:
38-
return None
39-
40-
# If accessibility is not enabled, the following API call will error.
21+
print(f"Can I see these print statements?????????????????????????????", file=sys.stderr, flush=True)
4122
try:
42-
return AXUIElementCreateApplication(pid)
43-
except Exception:
23+
ws = NSWorkspace.sharedWorkspace()
24+
regular_predicate = NSPredicate.predicateWithFormat_(
25+
f"activationPolicy == {NSApplicationActivationPolicyRegular}"
26+
)
27+
running_apps = ws.runningApplications().filteredArrayUsingPredicate_(
28+
regular_predicate
29+
)
30+
name_predicate = NSPredicate.predicateWithFormat_(
31+
f"localizedName contains[c] '{name}'"
32+
)
33+
filtered_apps = running_apps.filteredArrayUsingPredicate_(name_predicate)
34+
if filtered_apps.count() == 0:
35+
return None
36+
app = filtered_apps[0]
37+
pid = app.processIdentifier()
38+
if pid == -1:
39+
return None
40+
41+
ax_element = AXUIElementCreateApplication(pid)
42+
return ax_element
43+
44+
except Exception as e:
45+
print(f"Error finding browser: {e}", file=sys.stderr, flush=True)
4446
return None
4547

4648

0 commit comments

Comments
 (0)