birchill / 10ten-ja-reader

A browser extension to translate Japanese by hovering over words.
https://addons.mozilla.org/firefox/addon/10ten-ja-reader/
GNU General Public License v3.0
599 stars 45 forks source link

Not working for Bing Chat #1130

Closed nicolasmaia closed 1 year ago

nicolasmaia commented 1 year ago

10ten doesn't work on https://www.bing.com/search?q=Bing+AI

You might need either Edge or a useragent spoofer to be able to use Bing Chat, though

birtles commented 1 year ago

Thanks for reporting this. I can reproduce it. I'll look into it next week.

birtles commented 1 year ago

Seems to work fine in Firefox with a useragent spoof, but not in Edge.

Looks like it's related to Chromium not digging into shadow DOM for caretRangeFromPoint (and not supporting caretPositionFromPoint at all). Test case: https://8t4urf.codesandbox.io/

birtles commented 1 year ago

Seems like Safari has the same problem. Even document.elementsFromPoint doesn't dig into shadow trees. Instead we'll need to recursively do element(s)FromPoint on each shadow root until we get to some text. This could be quite a bit of work.

birtles commented 1 year ago

I've made some progress on this. It can now dig into these nested shadow DOM trees fairly successfully but it doesn't successfully mimic the layout of the shadow DOM content in a lot of cases. As a result in Bing chat, you can scan simple sentences, but once the footnote annotations appear they throw off the layout. It should be fixable but it's going to take a bit more work yet.