ashthespy / Atom-LaTeX

The only LaTeX package you need for typesetting with Atom.
https://atom.io/packages/atom-latex
MIT License
22 stars 9 forks source link

pdf.js closes unexpectedly #204

Closed acarril closed 5 years ago

acarril commented 5 years ago

Issue description

The PDF previewer window (which I believe is pdf.js) closes unexpectedly after a certain amount of time (not always the same).

EDIT: I'm aware this issue is similar to #200, but the solution proposed there doesn't work for me so I figured this might be a different underlying problem with the same symptom.

Steps to reproduce the issue

  1. Open any *.tex file in Atom
  2. Ctrl+s to save file and open PDF viewer
  3. Wait a certain amount of time, usually between 30-300 seconds.

What's the expected result?

What's the actual result?

Additional details / screenshot

Please let me know if you need any additional details. PDF viewer was working fine on the same machine when I had Debian, so it might be related to the current distro.

ashthespy commented 5 years ago

Hi, Can you try loading it in a PDF tab and sharing the output of the dev console? The window mode will not output anything on the dev console.

acarril commented 5 years ago

When I set it to view the PDF in a tab instead of closing spontaneously it just hangs. The console has the following output:

/home/alvaro/.atom/packages/atom-latex/lib/viewer.coffee:180 The provided value 'moz-chunked-arraybuffer' is not a valid enum value of type XMLHttpRequestResponseType.
/home/alvaro/.atom/packages/atom-latex/lib/viewer.coffee:180 %cElectron Security Warning (Insecure Resources)
/home/alvaro/.atom/packages/atom-latex/lib/viewer.coffee:180 %cElectron Security Warning (Insecure Content-Security-Policy)
/home/alvaro/.atom/packages/atom-latex/lib/viewer.coffee:180 PDF c47fd2c84b83f73f4ab675526ee61e4c [1.5 pdfTeX-1.40.19 / LaTeX with hyperref] (PDF.js: 1.9.426 [WebGL])
[Violation] 'requestAnimationFrame' handler took 56ms
[Violation] 'requestAnimationFrame' handler took 99ms
VM461 update-props.js:165 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
updateEventListeners @ VM461 update-props.js:165
module.exports @ VM461 update-props.js:17
patch @ VM464 patch.js:19
updateSync @ VM463 component-helpers.js:116
TextEditorComponent @ /usr/lib/atom/src/text-editor-component.js:181
getElement @ /usr/lib/atom/src/text-editor.js:4462
createView @ /usr/lib/atom/src/view-registry.js:138
getView @ /usr/lib/atom/src/view-registry.js:127
watchEditor @ /usr/lib/atom/node_modules/autocomplete-plus/lib/autocomplete-manager.js:152
subscriptions.add.atom.workspace.observeTextEditors @ /usr/lib/atom/node_modules/autocomplete-plus/lib/autocomplete-manager.js:183
onDidAddTextEditor @ /usr/lib/atom/src/workspace.js:634
simpleDispatch @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:64
emit @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:257
onDidAddPaneItem @ /usr/lib/atom/src/workspace.js:506
simpleDispatch @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:64
emit @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:257
didAddPaneItem @ /usr/lib/atom/src/pane-container.js:267
addItem @ /usr/lib/atom/src/pane.js:636
activateItem @ /usr/lib/atom/src/pane.js:578
open @ /usr/lib/atom/src/workspace.js:1049
VM461 update-props.js:165 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
updateEventListeners @ VM461 update-props.js:165
module.exports @ VM461 update-props.js:17
patch @ VM464 patch.js:19
updateSync @ VM463 component-helpers.js:116
TextEditorComponent @ /usr/lib/atom/src/text-editor-component.js:181
getElement @ /usr/lib/atom/src/text-editor.js:4462
createView @ /usr/lib/atom/src/view-registry.js:138
getView @ /usr/lib/atom/src/view-registry.js:127
watchEditor @ /usr/lib/atom/node_modules/autocomplete-plus/lib/autocomplete-manager.js:152
subscriptions.add.atom.workspace.observeTextEditors @ /usr/lib/atom/node_modules/autocomplete-plus/lib/autocomplete-manager.js:183
onDidAddTextEditor @ /usr/lib/atom/src/workspace.js:634
simpleDispatch @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:64
emit @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:257
onDidAddPaneItem @ /usr/lib/atom/src/workspace.js:506
simpleDispatch @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:64
emit @ /usr/lib/atom/node_modules/event-kit/dist/emitter.js:257
didAddPaneItem @ /usr/lib/atom/src/pane-container.js:267
addItem @ /usr/lib/atom/src/pane.js:636
activateItem @ /usr/lib/atom/src/pane.js:578
open @ /usr/lib/atom/src/workspace.js:1049
ashthespy commented 5 years ago

Looks similar to #188 - and both seem to be using Manjaro.

ashthespy commented 5 years ago

@acarril @jlbosse @rolandg Do let me know if the new update miraculously fixed this issue for you guys?

acarril commented 5 years ago

Unfortunately it didn't.

I see you updated the pdf.js version. Would it help if I load the same pdfs directly in pdf.js? To see if it's that program or something on atom-latex's side.

ashthespy commented 5 years ago

I doubt it's an issue with the pdfjs's core, especially since you say it happens with every pdf. I would reckon it's some electron based issue peculiar to your current distro. Either way, could you check if the pdf is being served properly?

# With a tex file open in the editor:
> atom_latex.latex.viewer.getUrl()
< true
> atom_latex.latex.viewer.url
< "http://127.0.0.1:57170/viewer.html?file=preview.pdf"

Ah, from what I see, the atom package offered via Arch uses a different version of electron (4.2.6-1) rather than what is normally bundled with Atom.

For example on my installation :

> atom.appVersion
< "1.38.2"
> process.versions  
> {
  res: "1.10.1-DEV"
  chrome: "61.0.3163.100"
  electron: "2.0.18"
  http_parser: "2.7.0"
  modules: "57"
  nghttp2: "1.25.0"
  node: "8.9.3"
  openssl: "1.0.2n"
  uv: "1.15.0"
  v8: "6.1.534.41"
  zlib: "1.2.11"
}

What does it look like for you? If that is indeed the issue, could you try if atom-editor-bin also gives you the same hanging behaviour?

VietTralala commented 5 years ago

I observe the same issues (randomly closing preview windows and hanging preview tab)

$lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:    16.04
Codename:   xenial

The atom console has the following output:

>viewer.coffee? [sm]:127 PDF 7a1cb2d2eb5cedc8737eae97194b8432 [1.5 pdfTeX-1.40.19 / LaTeX with hyperref package] (PDF.js: 2.1.266 [WebGL])
>atom_latex.latex.viewer.getUrl()
<true
>atom_latex.latex.viewer.url
<"http://127.0.0.1:35494/viewer.html?file=preview.pdf"
>atom.appVersion
<"1.39.0-beta2"
>process.versions
<{
ares: "1.14.0"
chrome: "66.0.3359.181"
electron: "3.1.10"
http_parser: "2.8.0"
modules: "64"
napi: "3"
nghttp2: "1.29.0"
node: "10.2.0"
openssl: "1.1.0h"
uv: "1.20.3"
v8: "6.6.346.32"
zlib: "1.2.11"
__proto__: Object
}

How can I help and provide more info?

ashthespy commented 5 years ago

Looks like Electron's webview is undergoing a lot of changes and that might be causing issues.

Could you try the following patch to check if it makes things better?

index e8d0e42..9bd7367 100644
--- a/lib/viewer.coffee
+++ b/lib/viewer.coffee
@@ -126,7 +126,10 @@ class Viewer extends Disposable

 class PDFView
   constructor: (url,title) ->
-    @element = document.createElement 'webview'
+    @element = document.createElement 'iframe'
+    @element.setAttribute 'width', '100%'
+    @element.setAttribute 'height', '100%'
+    @element.setAttribute 'frameborder', 0,
     @element.setAttribute 'src', url
     @element.addEventListener 'console-message', (e) -> console.log e.message
     @title = title
acarril commented 5 years ago

Looks like Electron's webview is undergoing a lot of changes and that might be causing issues.

Could you try the following patch to check if it makes things better?

index e8d0e42..9bd7367 100644
--- a/lib/viewer.coffee
+++ b/lib/viewer.coffee
@@ -126,7 +126,10 @@ class Viewer extends Disposable

 class PDFView
   constructor: (url,title) ->
-    @element = document.createElement 'webview'
+    @element = document.createElement 'iframe'
+    @element.setAttribute 'width', '100%'
+    @element.setAttribute 'height', '100%'
+    @element.setAttribute 'frameborder', 0,
     @element.setAttribute 'src', url
     @element.addEventListener 'console-message', (e) -> console.log e.message
     @title = title

I changed the lines in lib/viewer.coffee, but the problem still persists. As @vthuongt reports, the preview window closes and the preview tab hangs after a few seconds / minutes.

ashthespy commented 5 years ago

I changed the lines in lib/viewer.coffee, but the problem still persists. As @vthuongt reports, the preview window closes and the preview tab hangs after a few seconds / minutes.

@acarril is this with atom-editor-bin (https://github.com/James-Yu/Atom-LaTeX/issues/204#issuecomment-508809012) ?

acarril commented 5 years ago

I doubt it's an issue with the pdfjs's core, especially since you say it happens with every pdf. I would reckon it's some electron based issue peculiar to your current distro. Either way, could you check if the pdf is being served properly?

# With a tex file open in the editor:
> atom_latex.latex.viewer.getUrl()
< true
> atom_latex.latex.viewer.url
< "http://127.0.0.1:57170/viewer.html?file=preview.pdf"

I get the following:

> atom_latex.latex.viewer.getUrl()
< true
> atom_latex.latex.viewer.url
< "http://127.0.0.1:44129/viewer.html?file=preview.pdf"

Ah, from what I see, the atom package offered via Arch uses a different version of electron (4.2.6-1) rather than what is normally bundled with Atom.

For example on my installation :

> atom.appVersion
< "1.38.2"
> process.versions    
> {
  res: "1.10.1-DEV"
  chrome: "61.0.3163.100"
  electron: "2.0.18"
  http_parser: "2.7.0"
  modules: "57"
  nghttp2: "1.25.0"
  node: "8.9.3"
  openssl: "1.0.2n"
  uv: "1.15.0"
  v8: "6.1.534.41"
  zlib: "1.2.11"
}

What does it look like for you? If that is indeed the issue, could you try if atom-editor-bin also gives you the same hanging behaviour?

I get the following:

> atom.appVersion
< "1.38.2"
> process.versions  
< {http_parser: "2.9.2", node: "10.11.0", v8: "6.9.427.31-electron.0", uv: "1.23.0", zlib: "1.2.11", …}
ares: "1.15.0"
chrome: "69.0.3497.128"
cldr: "35.1"
electron: "4.2.6"
http_parser: "2.9.2"
icu: "64.2"
modules: "69"
napi: "3"
nghttp2: "1.36.0"
node: "10.11.0"
openssl: "1.1.0"
tz: "2019a"
unicode: "12.1"
uv: "1.23.0"
v8: "6.9.427.31-electron.0"
zlib: "1.2.11"
__proto__: Object

Then you're right in that I'm running a (wildly) different version of Electron. I'm going to try with atom-editor-bin and post the results.

acarril commented 5 years ago

Installing atom-editor-bin from AUR, as suggested by @ashthespy, fixed this issue for me. I wasn't aware of the discrepancy between the package in the official Arch repos and upstream Atom. Will stick with atom-editor-bin from now on!

acarril commented 5 years ago

Atom v1.39.0 has upgraded to Electron 3.1.10, which unfortunately makes this problem occur again. I suppose this can potentially become a larger issue now, since the official upstream version of Atom now comes with a conflicting version of Electron.

The solution (for me) is now to manually build Atom 1.38.2, the last stable release bundled with Electron 2.x, as atom-editor-bin in AUR now bundles an incompatible version of Electron.

Just in case anybody else needs to do it, I leave the steps below.

wget https://aur.archlinux.org/cgit/aur.git/snapshot/aur-ed73ace1502c9d1e747334fa424022c30c95296d.tar.gz
tar -xvf aur-ed73ace1502c9d1e747334fa424022c30c95296d.tar.gz
cd aur-ed73ace1502c9d1e747334fa424022c30c95296d
makepkg -s

After this you'll have a package ready for install. I just installed with:

pamac install atom-editor-bin-1.38.2-1-x86_64.pkg.tar.xz
dixr commented 5 years ago

The same issue now also affects my Ubuntu system (xfce). Details:

$ lsb_release -a
LSB Version:    core-9.20170808ubuntu1-noarch:printing-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
> atom_latex.latex.viewer.getUrl()
< true
> atom_latex.latex.viewer.url
< "http://127.0.0.1:42813/viewer.html?file=preview.pdf"
> atom.appVersion
< "1.39.1"
> process.versions
< {http_parser: "2.8.0", node: "10.2.0", v8: "6.6.346.32", uv: "1.20.3", zlib: "1.2.11", …}
ares: "1.14.0"
chrome: "66.0.3359.181"
electron: "3.1.10"
http_parser: "2.8.0"
modules: "64"
napi: "3"
nghttp2: "1.29.0"
node: "10.2.0"
openssl: "1.1.0h"
uv: "1.20.3"
v8: "6.6.346.32"
zlib: "1.2.11"
___dart__$dart_dartObject_ZxYxX_0_: JsObject {_jsObject: {…}}
__proto__: Object

Please let me know if you need more information.

UPDATE: The patch from #206 solved the issue for me

ashthespy commented 5 years ago

Should be fixed with v0.8.8