mliebelt / pgn-viewer

Simple PGN viewer with the necessary features to display chess games
GNU General Public License v3.0
155 stars 44 forks source link

Any different in android webview? #548

Open intothephone opened 1 month ago

intothephone commented 1 month ago

Many games mode works well in PC browser, and works well in mobile device browser, but not work in android webview. Following exceptions:

Uncaught TypeError: Cannot read properties of null (reading 'parentNode') at u (pgnViewer.js:1:1040639) at HTMLSelectElement. (pgnViewer.js:1:1039783)

The page is very simple(actually from examples):

This page can load properly in android webview, but when switching between games, above exceptions will come out and corresponding pgn could not be loaded. Any ideas?

intothephone commented 1 month ago

Interesting... I've found the root cause: variation

To be simple, if variations exist in the pgn, the switching between multiple games will not work. Take following pgn as an example:

[Event "test"] [Site "local"] [Date "2023.10.22"] [Round "1"] [White "human"] [Black "human"] [Result "*"] [ECO "C54"]

  1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Bd2 *

[Event "test"] [Site "local"] [Date "2023.07.04"] [Round "1"] [White "human"] [Black "human"] [Result "*"] [ECO "C59"]

  1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. Ng5 d5 5. exd5 Na5 6. d3 h6 7. Nf3 e4 8. Qe2 Nxc4 9. dxc4 Bc5 10. h3 (10. O-O O-O 11. Nfd2 Bg4 12. Qe1 Qd7 13. Nb3 Bf3 14. Bf4 Qg4 15. Bg3 Nh5 16. Nxc5 Nf4 17. Nxe4 Qh3) 10... O-O 11. Nh2 c6 12. dxc6 e3 13. Bxe3 Bxe3 14. fxe3 Ne4 *

I think it should be a bug.

intothephone commented 1 month ago

And more interesting, it works fine switching to the game with variations the first time, but after that, you'll never show this game again.

mliebelt commented 3 weeks ago

Wow, that is really a strange behavior. So I have to find out the local storage that keeps some not valid data, when switching to a new PGN. I did not liked the code in the beginning, but it seemed to be doable. I will hopefully find the reason after your well done analysis. Thank you !