coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.27k stars 5.51k forks source link

[Bug]: PDF not refresh and not sync while using the latex-workshop extension #6667

Closed sylvaticus closed 6 months ago

sylvaticus commented 6 months ago

Is there an existing issue for this?

OS/Web Information

Steps to Reproduce

code-server --install-extension latex-workshop Make a basic latex file and save it Click "View Latex PDF" in the "command section" Edit the tex and save Click again "View Latex PDF"

Expected

The PDF view in the tab should update

Actual

The PDF view in the tab is not updated

Logs

[14:49:01.214][Cacher][Watcher] "change" emitted on %WS1%/test.tex. [14:49:01.215][Cacher] Caching %WS1%/test.tex . [14:49:01.216][Cacher] Updated inputs of %WS1%/test.tex . [14:49:01.216][Cacher] Parse LaTeX AST: %WS1%/test.tex . [14:49:01.216][Build] Auto build starteddetecting the change of a file: %WS1%/test.tex . [14:49:01.216][Event] AUTO_BUILD_INITIATED: {"type":"onFileChange","file":"%WS1%/test.tex"} [14:49:01.216][Build] The document of the active editor: file://%WS1%/test.tex [14:49:01.216][Build] The languageId of the document: latex [14:49:01.216][Build] Building root file: %WS1%/test.tex [14:49:01.217][Build][Recipe] Build root file %WS1%/test.tex [14:49:01.217][Event] FILE_CHANGED: "%WS1%/test.tex" [14:49:01.232][Cacher] Parsed LaTeX AST: %WS1%/test.tex . [14:49:01.232][File] Calling kpsewhich to resolve article.cls . [14:49:01.288][Cacher] Updated elements in 55.72 ms: %WS1%/test.tex . [14:49:01.288][Event] FILE_PARSED: "%WS1%/test.tex" [14:49:01.289][Structure] Structure force updated with 2 root sections for %WS1%/test.tex . [14:49:01.289][Event] STRUCTURE_UPDATED [14:49:01.290][Extension] onDidSaveTextDocument triggered: file://%WS1%/test.tex [14:49:01.683][Extension] onDidSaveTextDocument triggered: file://%WS1%/test.tex [14:49:01.684][Build][Recipe] Preparing to run recipe: latexmk. [14:49:01.684][Build][Recipe] Prepared 1 tools. [14:49:01.685][Build][Recipe] outDir: %WS1% . [14:49:01.685][Build] Recipe step 1 The command is latexmk:["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%WS1%","%WS1%/test"]. [14:49:01.685][Build] env: {} [14:49:01.685][Build] root: %WS1%/test.tex [14:49:01.686][Build] cwd: %WS1% [14:49:01.693][Build] LaTeX build process spawned with PID 50033. [14:49:01.704][Cacher][Watcher] "change" emitted on %WS1%/test.tex. [14:49:01.706][Cacher] Caching %WS1%/test.tex . [14:49:01.706][Cacher] Updated inputs of %WS1%/test.tex . [14:49:01.706][Cacher] Parse LaTeX AST: %WS1%/test.tex . [14:49:01.706][Build] Auto build starteddetecting the change of a file: %WS1%/test.tex . [14:49:01.707][Event] AUTO_BUILD_INITIATED: {"type":"onFileChange","file":"%WS1%/test.tex"} [14:49:01.707][Build] Autobuild temporarily disabled. [14:49:01.707][Event] FILE_CHANGED: "%WS1%/test.tex" [14:49:01.724][Cacher] Parsed LaTeX AST: %WS1%/test.tex . [14:49:01.724][File] Calling kpsewhich to resolve article.cls . [14:49:01.780][Cacher] Updated elements in 55.81 ms: %WS1%/test.tex . [14:49:01.780][Event] FILE_PARSED: "%WS1%/test.tex" [14:49:01.781][Structure] Structure force updated with 2 root sections for %WS1%/test.tex . [14:49:01.781][Event] STRUCTURE_UPDATED [14:49:02.072][Parser][TexLog] Logged 0 messages. [14:49:02.073][Build] Finished a step in recipe with PID 50033. [14:49:02.073][Build] Successfully built %WS1%/test.tex . [14:49:02.073][Event] BUILD_DONE [14:49:02.073][Viewer] Call refreshExistingViewer: "%WS1%/test.pdf" . [14:49:02.073][Viewer] Refresh PDF viewer: %WS1%/test.pdf [14:49:02.074][Cacher] Parsing .fls %WS1%/test.fls . [14:49:02.077][Cacher] Found .aux %WS1%/test.tex from .fls %WS1%/test.fls , parsing. [14:49:02.078][Cacher] Parsed .aux %WS1%/test.tex . [14:49:02.078][Cacher] Parsed .fls %WS1%/test.fls . [14:49:02.488][Cacher][Watcher] "change" emitted on %WS1%/test.pdf after polling for 250 ms. [14:49:02.489][Viewer] Call refreshExistingViewer: "%WS1%/test.pdf" . [14:49:02.489][Viewer] Refresh PDF viewer: %WS1%/test.pdf [14:49:02.489][Event] FILE_CHANGED: "%WS1%/test.pdf"

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

Are you accessing code-server over a secure context?

Notes

The issue seems that the frame of the PDF preview of latex-workshop is itself not updated. Indeed latex-workshop correctly issue a "preview" command, but that, as well any "manual" attempts of updating/refreshing fails. The only thing to update the PDF is either to close the PDF preview tab and issue again the "View Latex PDF" command or to right click on the PDF -> This Frame -> Reload Frame.

Sync also doesn't work (in both directions)

sylvaticus commented 6 months ago

By the way, I am asking here as in the extension FAQ they say they simply they don't support vscode-server

code-asher commented 6 months ago

Does it work in Codespaces? If not I would use that angle to raise an issue. It seems unlikely to be specific to code-server, although not impossible, since we do patch some things around web views.

sylvaticus commented 6 months ago

Hello, yes I have tried it on https://github.com/sanjib-sen/WebLaTex and it works fine in a codespace settings (I have also opened an issue on the extension repository, but as expected it has been closed straigth away). A pity, as this extension would allow my colleagues to work on LateX on our computational server without installing anything...

benz0li commented 6 months ago

I can confirm @sylvaticus's findings.

It works in Codespaces with e.g. my Data Science Dev Containers (R verse) but it does not with JupyterLab R verse at https://coder.jupyter.b-data.ch.


Sample $\TeX$ file:

\documentclass{article}

\title{My first document}
\date{2024-02-09}
\author{John Doe}

\begin{document}
  \maketitle
  \newpage

  Hello World!

\end{document}
benz0li commented 6 months ago

@code-asher The LaTeX Workshop extension automatically re-builds the PDF when the $\TeX$ file changes.

In Codespaces, both the PDF in the VS Code tab (web view) and the PDF in the web browser (proxy + /viewer.html?file=pdf..whatsoever) get updated.
ℹ️ This does not happen with code-server.

benz0li commented 6 months ago

@sylvaticus Do you get any messages in your web console? I get many

[Log] Try to reconnect to LaTeX Workshop: (1/10). (latexworkshop.js, line 471)
[Log] Reconnected: WebSocket to LaTeX Workshop. (latexworkshop.js, line 465)
[Error] WebSocket connection to 'wss://coder.jupyter.b-data.ch/user/benz0li/code-server/proxy/37119/' failed: The operation couldn’t be completed. Socket is not connected
[Log] Closed: WebScocket to LaTeX Workshop. (latexworkshop.js, line 448)

plus

web-inspector_sources
sylvaticus commented 6 months ago

Here they are.. I have a feeling it may be related to some security settings on the PDF viewer iframe.. indeed in Firefox if I manually reaload the frame content I got the PDF updated..

console1 console2 console3

code-asher commented 6 months ago

Interesting, the web socket error seems promising, it would definitely explain why updates fail if the web socket has closed.

benz0li commented 6 months ago

Interesting, the web socket error seems promising, it would definitely explain why updates fail if the web socket has closed.

The logs from the JupyterLab container. I get many

[I 2024-02-10 08:00:55.325 ServerApp] 101 GET /user/benz0li/code-server/proxy/41311/ (benz0li@[redacted]) 2.14ms
[I 2024-02-10 08:00:55.325 ServerApp] Trying to establish websocket connection to ws://localhost:43011/proxy/41311/
[E 2024-02-10 08:00:55.336 ServerApp] Uncaught exception GET /user/benz0li/code-server/proxy/41311/ ([redacted])
    HTTPServerRequest(protocol='http', host='coder.jupyter.b-data.ch', method='GET', uri='/user/benz0li/code-server/proxy/41311/', version='HTTP/1.1', remote_ip='[redacted]')
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/site-packages/tornado/websocket.py", line 940, in _accept_connection
        await open_result
      File "/usr/local/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 853, in open
        return await super().open(path)
               ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 678, in open
        return await super().open(self.port, path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 557, in open
        return await self.proxy_open("localhost", port, proxied_path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 505, in proxy_open
        await start_websocket_connection()
      File "/usr/local/lib/python3.11/site-packages/jupyter_server_proxy/handlers.py", line 492, in start_websocket_connection
        self.ws = await pingable_ws_connect(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
    tornado.httpclient.HTTPClientError: HTTP 400: Bad Request

Maybe I can adjust something in my setup[^1]... maybe not.

[^1]: Traefik: TLS termination, proxy no. 1; JupyterHub: proxy no. 2; JupyterLab: proxy no. 3 (Jupyter Server Proxy); code-server: web app (proxy no. 4)

benz0li commented 6 months ago

@sylvaticus In your case, the web server seems to block mjs files. Should you use Nginx as TLS termination proxy, try adding the following to your server block:

types {
    application/javascript mjs;
}

Cross references:


Currently, mjs is not part ot Nginx's default MIME types.

docker run --rm -ti nginx bash -c 'cat /etc/nginx/mime.types'

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/avif                                       avif;
    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/wasm                                 wasm;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}
sylvaticus commented 6 months ago

Thank you @benz0li !

I have all my setup based on apache, do you know the equivalent way to set it in apache?

benz0li commented 6 months ago

I have all my setup based on apache, do you know the equivalent way to set it in apache?

See https://httpd.apache.org/docs/2.4/mod/mod_mime.html#addtype

sylvaticus commented 6 months ago

I have added AddType application/javascript mjs to apache configuration and host config, , restarted Apache (no errors), rebbotted the server, but I still have the mime error:

still_mime_error

Also I have a read error if I click the debug console: debugger

(don't know if it is related, or if it is related to issue #1828 ..)

sylvaticus commented 6 months ago

I have a feeling that it doesn't find the file, so it get an 404 error or so that has mimetype text/html... possible ?

sylvaticus commented 6 months ago

To complement, my setup is:

benz0li commented 6 months ago

I have a feeling that it doesn't find the file, so it get an 404 error or so that has mimetype text/html... possible ?

The problem is that https://comp.beta-lorraine.fr/:build/pdf.worker.mis is not a valid proxy path (URL).

It is the same with my setup: The browser console shows that it tries to GET https://coder.jupyter.b-data.ch/user/benz0li/code-server/proxy/build/pdf.worker.mjs.

It seems that the LaTeX Workshop extension does not support proxying on an already proxied path (i.e. a proxied sub-path) – done by jupyter-server-proxy/jupyter-vscode-proxy.

benz0li commented 6 months ago

With code-server, it works on localhost (127.0.0.1) both using http and https.
❗But only if not proxied by jupyter-server-proxy.

localhost, http

Host (Terminal)

docker run -it --rm -p 8888:8888 -p 47395:47395 glcr.b-data.ch/jupyterlab/r/verse:latest-devtools

ℹ️ Follow the instructions in the Terminal.

Container (JupyterLab Terminal)

code-server --bind-addr 0.0.0.0:47395

👉 Password: cat ~/.config/code-server/config.yaml

Host (Browser)

http://127.0.0.1:47395/?folder=/home/jovyan/projects

localhost, https

Host (Terminal)

docker run -it --rm -p 8888:8888 -p 47395:47395 -e GEN_CERT=yes glcr.b-data.ch/jupyterlab/r/verse:latest-devtools

ℹ️ Follow the instructions in the Terminal.

Container (JupyterLab Terminal)

code-server --bind-addr 0.0.0.0:47395 --cert ~/.local/share/jupyter/notebook.pem --cert-key ~/.local/share/jupyter/notebook.pem

👉 Password: cat ~/.config/code-server/config.yaml

Host (Browser)

https://127.0.0.1:47395/?folder=/home/jovyan/projects
benz0li commented 6 months ago

UPDATE, 2024-02-12T10:20+01:00: See https://github.com/coder/code-server/issues/6667#issuecomment-1938293048


When using the code-server launcher in JupyterLab, it does not work.

@code-server Previous post: Shows that this is not a problem with code-server.

@consideRatio I do not think this is a problem with the Jupyter Server Proxy[^1], either.

@James-Yu Problem: The LaTeX Workshop extension is not supporting proxied sub-paths.

[^1]: ShinyApps using secure websockets (wss) on a sub-path are proxied just fine by jupyter-server-proxy.

sylvaticus commented 6 months ago

@benz0li : do you think there is a way I can "redirect" that strange :build... path to the correct one using apache virtual host settings?

benz0li commented 6 months ago

@benz0li : do you think there is a way I can "redirect" that strange :build... path to the correct one using apache virtual host settings?

@sylvaticus IMHO this is a bug in the extension. How to fix when already installed:

cd /path/to/extensions/james-yu.latex-workshop-* \
  && cp -a viewer/viewer.mjs viewer/viewer.mjs.orig \
  && sed -i 's|\.\./web|\.\.|g' viewer/viewer.mjs \
  && sed -i 's|\.\./build|\./build|g' viewer/viewer.mjs

ℹ️ /path/to/extensions = The folder you have the extensions installed.


diff --git a/viewer/viewer.mjs.orig b/viewer/viewer.mjs
index 629241f..c0709e6 100644
--- a/viewer/viewer.mjs.orig
+++ b/viewer/viewer.mjs
@@ -4441,7 +4441,7 @@ const defaultOptions = {
     kind: OptionKind.API
   },
   cMapUrl: {
-    value: "../web/cmaps/",
+    value: "../cmaps/",
     kind: OptionKind.API
   },
   disableAutoFetch: {
@@ -4489,7 +4489,7 @@ const defaultOptions = {
     kind: OptionKind.API
   },
   standardFontDataUrl: {
-    value: "../web/standard_fonts/",
+    value: "../standard_fonts/",
     kind: OptionKind.API
   },
   verbosity: {
@@ -4501,7 +4501,7 @@ const defaultOptions = {
     kind: OptionKind.WORKER
   },
   workerSrc: {
-    value: "../build/pdf.worker.mjs",
+    value: "./build/pdf.worker.mjs",
     kind: OptionKind.WORKER
   }
 };
@@ -4525,7 +4525,7 @@ const defaultOptions = {
     kind: OptionKind.VIEWER
   };
   defaultOptions.sandboxBundleSrc = {
-    value: "../build/pdf.sandbox.mjs",
+    value: "./build/pdf.sandbox.mjs",
     kind: OptionKind.VIEWER
   };
 }
sylvaticus commented 6 months ago

Thank you very much, I'll going to test it today and report back..

On Mon, 12 Feb 2024, 07:35 Olivier Benz, @.***> wrote:

@benz0li https://github.com/benz0li : do you think there is a way I can "redirect" that strange :build... path to the correct one using apache virtual host settings?

@sylvaticus https://github.com/sylvaticus IMHO this is a bug in the extension. How to fix when already installed:

cd /path/to/extensions/james-yu.latex-workshop-* \ && cp -a viewer/viewer.mjs viewer/viewer.mjs.orig && sed -i 's|../||g' viewer/viewer.mjs

ℹ️ /path/to/extensions = The folder you have the extensions installed.

diff --git a/viewer/viewer.mjs.orig b/viewer/viewer.mjs

index 629241f..c0709e6 100644--- a/viewer/viewer.mjs.orig+++ b/viewer/viewer.mjs@@ -4441,7 +4441,7 @@ const defaultOptions = { kind: OptionKind.API }, cMapUrl: {- value: "../web/cmaps/",+ value: "web/cmaps/", kind: OptionKind.API }, disableAutoFetch: {@@ -4489,7 +4489,7 @@ const defaultOptions = { kind: OptionKind.API }, standardFontDataUrl: {- value: "../web/standard_fonts/",+ value: "web/standard_fonts/", kind: OptionKind.API }, verbosity: {@@ -4501,7 +4501,7 @@ const defaultOptions = { kind: OptionKind.WORKER }, workerSrc: {- value: "../build/pdf.worker.mjs",+ value: "build/pdf.worker.mjs", kind: OptionKind.WORKER } };@@ -4525,7 +4525,7 @@ const defaultOptions = { kind: OptionKind.VIEWER }; defaultOptions.sandboxBundleSrc = {- value: "../build/pdf.sandbox.mjs",+ value: "build/pdf.sandbox.mjs", kind: OptionKind.VIEWER }; }

— Reply to this email directly, view it on GitHub https://github.com/coder/code-server/issues/6667#issuecomment-1938126908, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAP3DZ5T35GDM4E5RBNV6P3YTGZ3ZAVCNFSM6AAAAABC7ZDSNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZYGEZDMOJQHA . You are receiving this because you were mentioned.Message ID: @.***>

benz0li commented 6 months ago

@sylvaticus @consideRatio @James-Yu I have whitelisted your GitHub accounts at https://coder.jupyter.b-data.ch ℹ️ Extensions are installed at system level in /opt/code-server/lib/vscode/extensions.

Maybe someone more experienced with web technologies finds out why the websocket to LaTeX Workshop always closes and there is an indefinite loop of

Try to reconnect to LaTeX Workshop: (1/10).
Reconnected: WebSocket to LaTeX Workshop.
Closed: WebScocket to LaTeX Workshop.
sylvaticus commented 6 months ago

@benz0li : yep, I have applied your patch but I have the same outcome on my server.....

benz0li commented 6 months ago

ℹ️ If I start code-server instead of JupyterLab and put only Traefik in front of it, everything works perfectly – even when code-server is proxied on a path.
👉 The culprit seems to be Jupyter Server Proxy after all. And it comes back to https://github.com/coder/code-server/issues/6667#issuecomment-1936910269.

@consideRatio Where to file the issue: https://github.com/jupyterhub/jupyter-server-proxy or https://github.com/tornadoweb/tornado?
❓ Is any additional info required besides what has already been stated in this issue?

FYI @bdarnell


Maybe related to

benz0li commented 6 months ago

@sylvaticus Please close in favour of https://github.com/jupyterhub/jupyter-server-proxy/issues/445.

IMHO this issue is not caused by code-server.

sylvaticus commented 6 months ago

What about your patch on the LaTeX WorkShop extension? Should it still apply or not ?

benz0li commented 6 months ago

What about your patch on the LaTeX WorkShop extension? Should it still apply or not ?

It [also] works without the patch.

The invalid 'proxy path'/URL is only requested once. Subsequent requests use the correct 'proxy path'/URL.

benz0li commented 6 months ago

@sylvaticus Jupyter Server Proxy, indeed: https://github.com/jupyterhub/jupyter-server-proxy/pull/446