nyxt icon indicating copy to clipboard operation
nyxt copied to clipboard

Visual mode doesn't work in pages containing Shadow DOMs

Open heiwiper opened this issue 2 years ago • 8 comments

Describe the bug

Visual mode generates errors when browsing web pages containing Shadow DOMs. This issue is still persistent after mergning the shadow hinting branch from PR #3001. This is probably due to how the function window.getSelection() from the browser API is implemented. Some browsers such as Firefox seem to cross shadow boundaries when implementing the same function which can be tested in the following website https://developer.servicenow.com/dev.do by clicking on a heading and calling the function window.getSelection() in the console, it should get an empty selection object on Nyxt Browser and Epiphany which isn't the case for Firefox.

Precise recipe to reproduce the issue

This recipe assumes changes from PR #3001 are merged and qs-nyxt-id macro is replaced with rqs-nyxt-id in function dom/set-caret-on-start.

  1. Visit the website https://developer.servicenow.com/dev.do which contains Shadow DOMs.
  2. Call the command visual-mode and type one of the hints that are displayed.
  3. Call the command forward-char.

Information

  • OS name+version: Debian GNU/Linux 12 (bookworm) x86_64
  • Graphics card and driver: AMD ATI Radeon Vega Series / Radeon Vega Mobile Series
  • Desktop environment / Window manager name+version: Xfce 4.18 / Xfwm4
  • How you installed Nyxt (Guix pack, package manager, build from source): build from source
  • Information from show-system-information:
Nyxt version: 3.0.0-56-g82babe9a3
Renderer: GI-GTK
Operating system kernel: Linux 6.1.0-7-amd64
Lisp implementation: SBCL 2.2.9.debian (Dynamic space size: 3221225472)
Features: (:NYXT-GI-GTK :NYXT-GTK :NYXT-UNSTABLE :NYXT-G82BABE9A3 :NYXT-3.0.0 :NYXT-3.0 :NYXT-3 :NYXT-3.0.0-56-G82BABE9A3 :SLYNK :PLUMP-UTF-32 :PARENSCRIPT :NSYMBOLS :FSET-EXT-STRINGS :GLOBAL-VARS :DECLARE-TYPES :NAMED-READTABLES :SWANK :CL-FAD :LPARALLEL :21BIT-CHARS :CUSTOM-HASH-TABLE-NATIVE :CL-PPCRE-UNICODE :CL-UNICODE :CHUNGA :FLEXI-STREAMS :CL-PPCRE :WEBKIT2 :WEBKIT2-2.40 :WEBKIT2-CORS-ALLOWLIST :WEBKIT2-PASTE-PLAINTEXT :WEBKIT2-TRACKING :WEBKIT2-MUTE :WEBKIT2-EMOJI :WEBKIT2-MEDIA :WEBKIT2-SANDBOXING :GTK-3-22 :GTK-3-20 :GTK-3-18 :GTK-3-16 :GTK-3-14 :GTK-3-12 :GTK-3-10 :GTK-3-8 :GTK-3-6 :GTK-3-4 :GTK :GDK-3-22 :GDK-3-20 :GDK-3-18 :GDK-3-16 :GDK-3-14 :GDK-3-12 :GDK-3-10 :GDK-3-8 :GDK-3-6 :GDK-3-4 :CAIRO-1-10 :CAIRO-1-12 :GDK-PIXBUF :CLOSER-MOP :GLIB-2-30 :GLIB-2-32 :GLIB-2-34 :GLIB-2-36 :GLIB-2-38 :GLIB-2-40 :GLIB-2-42 :GLIB-2-44 :GLIB-2-46 :GLIB-2-48 :GLIB-2-50 :GLIB-2-52 :GLIB-2-54 :GLIB-2-56 :GLIB-2-58 :GLIB :BORDEAUX-THREADS :LPARALLEL.WITH-CLTL2 :LPARALLEL.WITH-CAS :LPARALLEL.WITH-STEALING-SCHEDULER :SPLIT-SEQUENCE CFFI-FEATURES:FLAT-NAMESPACE CFFI-FEATURES:X86-64 CFFI-FEATURES:UNIX :CFFI CFFI-SYS::FLAT-NAMESPACE ALEXANDRIA::SEQUENCE-EMPTYP :FAST-IO-SV :FAST-IO :CL-JSON-CLOS :CL-JSON :SBCL-USES-SB-ROTATE-BYTE CHIPZ-SYSTEM:GRAY-STREAMS :THREAD-SUPPORT :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-UNIX :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :X86-64 :GENCGC :64-BIT :ANSI-CL :COMMON-LISP :ELF :IEEE-FLOATING-POINT :LINUX :LITTLE-ENDIAN :PACKAGE-LOCAL-NICKNAMES :SB-CORE-COMPRESSION :SB-LDB :SB-PACKAGE-LOCKS :SB-THREAD :SB-UNICODE :SBCL :UNIX)

ASDF version: 3.3.1
ASDF registries: (NYXT-SOURCE-REGISTRY ENVIRONMENT-SOURCE-REGISTRY)
Critical dependencies: (/home/heiwiper/quicklisp/local-projects/nyxt/_build/cl-cffi-gtk/gtk/cl-cffi-gtk.asd /home/heiwiper/quicklisp/local-projects/nyxt/_build/cl-gobject-introspection/cl-gobject-introspection.asd /home/heiwiper/quicklisp/local-projects/nyxt/_build/cl-webkit/webkit2/cl-webkit2.asd)

Output when started from a shell

Nyxt version 3.0.0-67-ge9afd29e6
<INFO> [23:36:10] Source location: #P"/home/heiwiper/quicklisp/local-projects/nyxt/"
<INFO> [23:36:10] Loading Lisp file #P"/home/heiwiper/.config/nyxt/auto-config.3.lisp".
<INFO> [23:36:10] Listening to socket: #P"/run/user/1000/nyxt/nyxt.socket"
<INFO> [23:36:10] GTK extensions directory: #P"/home/heiwiper/quicklisp/local-projects/nyxt/libraries/web-extensions/"
<INFO> [23:36:10] GTK extensions directory: #P"/home/heiwiper/quicklisp/local-projects/nyxt/libraries/web-extensions/"
<INFO> [23:36:10] Loading #P"/home/heiwiper/.local/share/nyxt/history/default.lisp".
<INFO> [23:36:10] Restoring 4 buffers from history.
<INFO> [23:36:10] Loading #P"/home/heiwiper/.local/share/nyxt/auto-rules.lisp".
<INFO> [23:36:13] Pressed keys: C-x

** (process:2): WARNING **: 23:36:13.892: Error writing credentials to socket: Error sending message: Broken pipe

** (process:2): WARNING **: 23:36:13.924: Error writing credentials to socket: Error sending message: Broken pipe
<INFO> [23:36:15] Loading "https://developer.servicenow.com/dev.do".
<INFO> [23:36:33] Finished loading "https://developer.servicenow.com/dev.do".
<INFO> [23:36:35] Visual mode enabled.
<WARN> [23:36:42] Warning: JavaScript error: GError: Domain: "WebKitJavascriptError", Code: 699, Message: https://developer.servicenow.com/dev.do:3:51: TypeError: null is not an object (evaluating 'window.getSelection().focusNode.parentElement')

heiwiper avatar Jun 18 '23 22:06 heiwiper

It seems that the Selection API for crossing Shadow boundaries is already implemented in webkit-2.41.2 according to this PR. I will need to test against that version.

heiwiper avatar Jun 18 '23 23:06 heiwiper

@heiwiper we currently ship Nyxt with WebKitGTK 2.40.1/2. WebKitGTK 2.41.2 was released in April, but it's a development release and we only use stable one.

aadcg avatar Jun 19 '23 08:06 aadcg

Do you think we should add a workaround in the meantime ?

heiwiper avatar Jun 19 '23 08:06 heiwiper

Honestly, I'd say no. As you can from our issues, no one has even bumped into it. We can get a free meal if we wait long enough, so let's take advantage from it :)

aadcg avatar Jun 19 '23 08:06 aadcg

@heiwiper the feature you mention should now be part of the WebKitGTK version we're shipping. However, I believe the issue still persists. If you're still interested, could you confirm? Thanks.

aadcg avatar Aug 14 '24 08:08 aadcg

I will test it this weekend and will let you know.

heiwiper avatar Aug 14 '24 09:08 heiwiper

@aadcg it seems like this issue is still reproducible when testing against master branch. I would love to help resolve it but I don't have much time currently.

heiwiper avatar Aug 18 '24 22:08 heiwiper

@heiwiper, thanks for confirming that you can reproduce it. Then it seems that it may not be related to the Selection API. Don't worry about fixing it, you have already helped.

aadcg avatar Aug 21 '24 10:08 aadcg