Accessibility

Accessibility concerns in Electron applications are similar to those of websites because they’re both ultimately HTML.

Manually enabling accessibility features

Electron applications will automatically enable accessibility features in the presence of assistive technology (e.g. JAWS on Windows or VoiceOver on macOS). See Chrome’s accessibility documentation for more details.

You can also manually toggle these features either within your Electron application or by setting flags in third-party native software.

Using Electron’s API

By using the app.setAccessibilitySupportEnabled(enabled) API, you can manually expose Chrome’s accessibility tree to users in the application preferences. Note that the user’s system assistive utilities have priority over this setting and will override it.

Within third-party software

macOS

On macOS, third-party assistive technology can toggle accessibility features inside Electron applications by setting the AXManualAccessibility attribute programmatically:

Using Objective-C:

  1. CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");
  2. + (void)enableAccessibility:(BOOL)enable inElectronApplication:(NSRunningApplication *)app
  3. {
  4. AXUIElementRef appRef = AXUIElementCreateApplication(app.processIdentifier);
  5. if (appRef == nil)
  6. return;
  7. CFBooleanRef value = enable ? kCFBooleanTrue : kCFBooleanFalse;
  8. AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, value);
  9. CFRelease(appRef);
  10. }

Using Swift:

  1. import Cocoa
  2. let name = CommandLine.arguments.count >= 2 ? CommandLine.arguments[1] : "Electron"
  3. let pid = NSWorkspace.shared.runningApplications.first(where: {$0.localizedName == name})!.processIdentifier
  4. let axApp = AXUIElementCreateApplication(pid)
  5. let result = AXUIElementSetAttributeValue(axApp, "AXManualAccessibility" as CFString, true as CFTypeRef)
  6. print("Setting 'AXManualAccessibility' \(error.rawValue == 0 ? "succeeded" : "failed")")