Skip to content

AX: Add the ability to dump the accessibility tree via notifyutil #47299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

twilco
Copy link
Contributor

@twilco twilco commented Jun 27, 2025

3bcec6c

AX: Add the ability to dump the accessibility tree via notifyutil
https://bugs.webkit.org/show_bug.cgi?id=295101
rdar://154490712

Reviewed by Joshua Hoffman.

After this commit, with a build of WebKit that has ENABLE(TREE_DEBUGGING), one can run:

notifyutil -p com.apple.WebKit.showAccessibilityTree

To dump the accessibility tree on-demand.

Also, when ENABLE(INCLUDE_IGNORED_IN_CORE_AX_TREE), this commit changes streamAXCoreObject to print the parent object
(including ignored), and streamSubtree to print ignored children.

* Source/WebCore/accessibility/AXCoreObject.h:
(WebCore::AXCoreObject::parentInCoreTree const):
* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::streamSubtree):
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::showAccessibilityTree):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AccessibilityObject.h:
(WebCore::AccessibilityObject::parentInCoreTree const): Deleted.
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateNode):
* Source/WebCore/page/cocoa/PageCocoa.mm:
(WebCore::Page::platformInitialize):
* Source/WebCore/rendering/RenderObject.cpp:
(WebCore::printAccessibilityTreeForLiveDocuments):
* Source/WebCore/rendering/RenderObject.h:
* Source/WebKit/Resources/cocoa/NotificationAllowList/ForwardedNotifications.def:

Canonical link: https://commits.webkit.org/296746@main

dca0422

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@twilco twilco requested a review from cdumez as a code owner June 27, 2025 15:04
@twilco twilco self-assigned this Jun 27, 2025
@twilco twilco added the Accessibility For bugs related to accessibility. label Jun 27, 2025
Copy link
Contributor

@minorninth minorninth left a comment

Choose a reason for hiding this comment

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

Love it!

@@ -1053,4 +1053,6 @@ bool isVisibilityHidden(const RenderStyle&);

WTF::TextStream& operator<<(WTF::TextStream&, AXNotification);

void showAccessibilityTree(Document&);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about dumpAccessibilityTreeToStderr or something more specific? Show makes it sound like it will be visual

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agreed. The reason I chose this name is to follow the pattern of the other notifyutil tree dump functions, e.g.:

showLayerTree

showRenderTree

showPaintOrderTree

But I don't think we really need to follow the pattern in this case, so I'll change it.

continue;
if (document->frame()) {
if (document->frame()->isRootFrame())
WTFLogAlways("Accessibility tree for root document %p %s", document.ptr(), document->url().string().utf8().data());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does WTFLogAlways do the same as fprintf to stderr, with the same buffering and everything? I think it'd be best if all of the code that logs uses the same mechanism

Copy link
Contributor Author

@twilco twilco Jun 27, 2025

Choose a reason for hiding this comment

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

WTFLogAlways is a thin-wrapper over this:

// Assertions.cpp
void WTFLogAlwaysV(const char* format, va_list args)
{
    vprintf_stderr_with_trailing_newline(nullptr, format, args);
}

So seems like it's always stderr?

I mostly chose WTFLogAlways to follow the pattern of the several other similar "dump tree" methods, e.g.:

printLayerTreeForLiveDocuments

printRenderTreeForLiveDocuments

printPaintOrderTreeForLiveDocuments

...and a few others

Would you prefer we explicitly fprintf(stderr, ""); here?

Copy link
Contributor

Choose a reason for hiding this comment

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

If they're both directly printing to stderr then it's fine. I've just been bitten by, e.g. mixing cerr and stderr because they have separate buffering.

@twilco twilco force-pushed the eng/AX-Add-the-ability-to-dump-the-accessibility-tree-via-notifyutil branch from 19c7c72 to dca0422 Compare June 27, 2025 15:55
@twilco twilco added the merge-queue Applied to send a pull request to merge-queue label Jun 27, 2025
https://bugs.webkit.org/show_bug.cgi?id=295101
rdar://154490712

Reviewed by Joshua Hoffman.

After this commit, with a build of WebKit that has ENABLE(TREE_DEBUGGING), one can run:

notifyutil -p com.apple.WebKit.showAccessibilityTree

To dump the accessibility tree on-demand.

Also, when ENABLE(INCLUDE_IGNORED_IN_CORE_AX_TREE), this commit changes streamAXCoreObject to print the parent object
(including ignored), and streamSubtree to print ignored children.

* Source/WebCore/accessibility/AXCoreObject.h:
(WebCore::AXCoreObject::parentInCoreTree const):
* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::streamSubtree):
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::showAccessibilityTree):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AccessibilityObject.h:
(WebCore::AccessibilityObject::parentInCoreTree const): Deleted.
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateNode):
* Source/WebCore/page/cocoa/PageCocoa.mm:
(WebCore::Page::platformInitialize):
* Source/WebCore/rendering/RenderObject.cpp:
(WebCore::printAccessibilityTreeForLiveDocuments):
* Source/WebCore/rendering/RenderObject.h:
* Source/WebKit/Resources/cocoa/NotificationAllowList/ForwardedNotifications.def:

Canonical link: https://commits.webkit.org/296746@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/AX-Add-the-ability-to-dump-the-accessibility-tree-via-notifyutil branch from dca0422 to 3bcec6c Compare June 27, 2025 19:48
@webkit-commit-queue
Copy link
Collaborator

Committed 296746@main (3bcec6c): https://commits.webkit.org/296746@main

Reviewed commits have been landed. Closing PR #47299 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 3bcec6c into WebKit:main Jun 27, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility For bugs related to accessibility.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants