Skip to content

Allow browse mode's native selection mode in Chromium-based browsers that can support it.#17838

Merged
SaschaCowley merged 3 commits into
masterfrom
allowNativeSelectionModeForchromium
Mar 18, 2025
Merged

Allow browse mode's native selection mode in Chromium-based browsers that can support it.#17838
SaschaCowley merged 3 commits into
masterfrom
allowNativeSelectionModeForchromium

Conversation

@michaelDCurran

Copy link
Copy Markdown
Member

Link to issue number:

Fixes #17591

Summary of the issue:

In #15830, NVDA browse mode gained a new native Selection Mode (toggled on with NVDA+shift+f10) which caused the browser's underlying native selection (DOM selection) to mirror the browse mode virtual selection. Although this worked well in Firefox, it had to be forcefully disabled for Chromium-based browsers as there were major bugs in Chromiums implementation of IAccessibleTextSelectionContainer.
As of Chromium 134 stable, all known bugs have been addressed, thus NVDA should allow native selection mode in Chromium-based browsers where possible.

Description of user facing changes

NVDA browse mode's native selection mode (NVDA+shift+f10) can now be enabled in any browser based on Chromium 134 or newer.

Description of development approach

  • The Chromium virtualBuffer is no longer marked as not supporting native app selection mode.
  • toggling native selection mode on now firstly tries to clear the native selection before updating it, and also catches more errors, ensuring that native selection mode is truly supported when enabling.

Testing strategy:

  • In Firefox, visited nvaccess.org, enabled native selection mode, selected the navbar, copied to clipboard, and pasted to an editor to verify all expected content was there.
  • In Chrome134, visited nvaccess.org, enabled native selection mode, selected the navbar, copied to clipboard, and pasted to an editor to verify all expected content was there.
  • In MS Edge 135, visited nvaccess.org, enabled native selection mode, selected the navbar, copied to clipboard, and pasted to an editor to verify all expected content was there.
  • In VS Code February update (Chromium 132), in browse mode tried to enable native selection mode, which reported as not supported as expected.

Known issues with pull request:

None known.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

…ased browsers where supported (Chromium 134 and newer). Also try clearing the selection and handle extra errors when first enabling to ensure native selection mode is fully supported.

@SaschaCowley SaschaCowley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work!

@nvdaes

nvdaes commented Mar 18, 2025

Copy link
Copy Markdown
Collaborator

Thanks @michaelDCurran . This is amazing! I've reviewed this PR and tested it in Thorium EPUB reader, and when this is merged we can use a new feature to select text and create bookmarks with the selected text as the bookmark label, and maybe also annotations.
Please @@danielweck, take care of this for Thorium.

Comment thread source/browseMode.py
self.clearAppSelection()
self.updateAppSelection()
except NotImplementedError:
except (NotImplementedError, COMError):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except (NotImplementedError, COMError):
except (NotImplementedError, COMError):

What about adding an explanatiry ui.message here? An exception can happen if we try to select all pressing control+aand the document contain elements inside and outside a frame, like in Thorium Reader.

Traceback (most recent call last):
File "scriptHandler.py", line 300, in executeScript
script(gesture)
File "cursorManager.py", line 474, in script_selectLine_forward
self._selectionMovementScriptHelper(unit=textInfos.UNIT_LINE, direction=1)
File "cursorManager.py", line 458, in _selectionMovementScriptHelper
self.selection = newInfo
^^^^^^^^^^^^^^
File "browseMode.py", line 1750, in _set_selection
super(BrowseModeDocumentTreeInterceptor, self)._set_selection(info)
File "cursorManager.py", line 132, in _set_selection
info.updateSelection()
File "textInfos\offsets.py", line 747, in updateSelection
return self._setSelectionOffsets(self._startOffset, self._endOffset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "virtualBuffers\gecko_ia2.py", line 55, in _setSelectionOffsets
self.obj.updateAppSelection()
File "virtualBuffers\gecko_ia2.py", line 723, in updateAppSelection
self._getEndSelection(ia2Sel, selFields)
File "virtualBuffers\gecko_ia2.py", line 691, in _getEndSelection
raise NotImplementedError("No ia2TextEndOffset in any field")
NotImplementedError: No ia2TextEndOffset in any field

Comment thread source/browseMode.py
self.updateAppSelection()
except NotImplementedError:
except (NotImplementedError, COMError):
log.debugWarning("updateAppSelection failed", exc_info=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
log.debugWarning("updateAppSelection failed", exc_info=True)
# Translators: Message presented when update native selection fails in Browse Mode.
ui.message(_("Update native selection has failed, try to adjust the selection range"))
log.debugWarning("updateAppSelection failed", exc_info=True)

@amirmahdifard

Copy link
Copy Markdown

hello everyone. I have a long time qustion. can this feature only be enabled using nvda shift f10? or can it also be enabled with an option in settings? thanks

@michaelDCurran

Copy link
Copy Markdown
Member Author

This PR specifically just focuses on extending the current support from Firefox to now also Chromium.
I think questions and suggestions around enabling this by default, and how it can report issues where it cannot update native selection properly should be talked about in separate issues or discussions. I would like to see it on by default eventually, and I agree some corner cases could be better reported. But I think we need to better understand those corner cases first. I think we need to think about the UX carefully.

@nvdaes

nvdaes commented Mar 18, 2025

Copy link
Copy Markdown
Collaborator

When this is merged, I can open an issue, if needed requesting better handling of reporting selection failures.
Hope this can be merged soon.

@michaelDCurran michaelDCurran added this to the 2025.1 milestone Mar 18, 2025

@nvdaes nvdaes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Given the scope of this PR, for me it's OK.

@SaschaCowley SaschaCowley merged commit 6a53882 into master Mar 18, 2025
@SaschaCowley SaschaCowley deleted the allowNativeSelectionModeForchromium branch March 18, 2025 22:08
@tmthywynn8

Copy link
Copy Markdown

I'm using Beta1 of NVDA 2025.1, and occasionally I get "Native selection mode unsupported in this document" when attempting to enable, however closing and reopening the browser magically allows me to enable native selection again:

INFO - globalCommands.script_navigatorObject_devInfo (17:02:33.928) - MainThread (12188):
Developer info for navigator object:
name: 'Skip to content'
role: LINK
processID: 1152
roleText: None
states: LINKED, FOCUSABLE, INTERNAL_LINK
isFocusable: True
hasFocus: False
Python object: <NVDAObjects.IAccessible.ia2Web.Ia2Web object at 0x05D8A610>
Python class mro: (<class 'NVDAObjects.IAccessible.ia2Web.Ia2Web'>, <class 'NVDAObjects.IAccessible.IAccessible'>, <class 'NVDAObjects.window.Window'>, <class 'NVDAObjects.NVDAObject'>, <class 'documentBase.TextContainerObject'>, <class 'baseObject.ScriptableObject'>, <class 'baseObject.AutoPropertyObject'>, <class 'garbageHandler.TrackedObject'>, <class 'object'>)
description: None
location: RectLTWH(left=4, top=108, width=1, height=1)
value: 'https://github.com/nvaccess/nvda/pull/17838#start-of-content'
TextInfo: <class 'NVDAObjects.IAccessible.IA2TextTextInfo'>
appModule: AppModule(appModuleHandler, appName='msedge', processID=1152)
appModule.productName: 'Microsoft Edge'
appModule.productVersion: '135.0.3179.85'
appModule.helperLocalBindingHandle: c_long(116590576)
appModule.appArchitecture: 'AMD64'
windowHandle: 788606
windowClassName: 'Chrome_RenderWidgetHostHWND'
windowControlID: 206800608
windowStyle: 1445986304
extendedWindowStyle: 32
windowThreadID: 5812
windowText: 'Chrome Legacy Window'
displayText: ''
IAccessibleObject: <POINTER(IAccessible2) ptr=0xb5472ec at 5d71b20>
IAccessibleChildID: 0
IAccessible event parameters: windowHandle=788606, objectID=-4, childID=-173345
IAccessible accName: 'Skip to content'
IAccessible accRole: ROLE_SYSTEM_LINK
IAccessible accState: STATE_SYSTEM_FOCUSABLE, STATE_SYSTEM_LINKED, STATE_SYSTEM_VALID (5242880)
IAccessible accDescription: None
IAccessible accValue: 'https://github.com/nvaccess/nvda/pull/17838#start-of-content'
IAccessible2 windowHandle: 788606
IAccessible2 uniqueID: -173345
IAccessible2 role: ROLE_SYSTEM_LINK
IAccessible2 states: IA2_STATE_OPAQUE (1024)
IAccessible2 attributes: 'display:block;tag:a;name-from:contents;class:p-3 color-bg-accent-emphasis color-fg-on-emphasis show-on-focus js-skip-to-content;text-align:left;'
IAccessible2 relations: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Support native selection mode in Chromium

5 participants