yzane / vscode-markdown-pdf

Markdown converter for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf
Other
1.01k stars 206 forks source link

error when exporting pdf #249

Open QCShen opened 3 years ago

QCShen commented 3 years ago

I got an error when exporting pdf. image

This error only occurs on the version higher than v1.2.0. (on versions that prior to 1.2.1 everything is ok.)

Does anyone experience the same issue?

fwhv2042 commented 3 years ago

This error looks a lot like this other: #185

Try following these steps: CTRL+shift+p > settings.json > add the line: "markdown-pdf.executablePath": "C:\chrome.exe" > restart vscode

QCShen commented 3 years ago

Of course I've done this several times from the beginning. Error still occurred, but message changed if I set the path to chrome.exe. (I'm using Edge for default browser) image

No idea what is the read target. (temp html or chrome.exe?)

fwhv2042 commented 3 years ago

OK. I'll try to debug. So, please let me know your environment.

  1. OS (Windows 10? Mac? Ubuntu?)
  2. Chome browser version
  3. Visual Studio version

And please try to make a pdf with the attached file. test.md

QCShen commented 3 years ago

Thank you so much. @fwhv2042 Here is my environment. OS: Windows 10 Chrome: Always up to date (now 90) VSCode: Always up to date (now 1.56 user setup)

Trying make pdf from attached test.md also output the same error.

fwhv2042 commented 3 years ago

Thank you for your information. It ’s the same environment as me. Sorry to trouble you, but I want you to try one thing.

https://github.com/yzane/vscode-markdown-pdf/blob/837ad2afd32768024f14565a3de2d24c16e9140e/extension.js#L399-L404

Please try changing the code as below. (Sorry, if it has already been done)

var options = {
          executablePath: vscode.workspace.getConfiguration('markdown-pdf')['executablePath'] || puppeteer.executablePath(),
          args: ['--lang='+vscode.env.language, '--no-sandbox', '--disable-setuid-sandbox'],
          ignoreDefaultArgs: ['--disable-extensions'],
          // Setting Up Chrome Linux Sandbox
          // https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
      };

The difference is as follows. ignoreDefaultArgs: ['--disable-extensions'],

fwhv2042 commented 3 years ago

If the above method fails, try replacing it( C:\Users\ username \.vscode\extensions\yzane.markdown-pdf-1.4.4 ) with this file and running export pdf. extension.zip

I have included an error message, so please let me know the result.

QCShen commented 3 years ago

Sorry for the late response. I added the ignoreDefaultArgs option but nothing changed. I also replaced the extension.js with the one you attached, after showing 'exportHtml OK', 'launch OK' and 'newPage OK', the same error message was displayed. 'page.pdf OK' message was not displayed. image

Does this mean that the browser extensions I installed have nothing to do with this issue?

QCShen commented 3 years ago

I disabled the "markdown-pdf.styles" option in VSCode setting, and comment out all the options except "path" , run on your test.md, the same error occurred. test_tmp.zip

Attached is the temporary html file.

image

fwhv2042 commented 3 years ago

Thank you for trying!! Probably a browser issue. I think that the markdownpdf extension is working fine. So, next step. Let me decide if it's a browser issue.

Please install Microsoft chromium edge. Microsoft chromium edge download

And please set "markdown-pdf.executablePath": C:\msedge.exe

QCShen commented 3 years ago

My default browser is "Microsoft Edge based on Chromium". All the behavior I reported above was basically based on "Microsoft Edge based on Chromium", except my 2nd post on replying to your request to setting "markdown-pdf.executablePath" to chrome.

The error is produced by puppeteer, so I tried replacing the puppeteer(which is "puppeteer-core": "^2.1.1") used in markdownpdf 1.44 with the one(which is "puppeteer": "^1.3.0") used in markdownpdf 1.2.0, and everything goes well, PDF is successfully generated. This approach also worked fine to fix the error when using markdownpdf 1.2.1 who uses "puppeteer": "^1.20.0".

It seems that the error was produced by puppeteer newer the v1.3, and I traced the puppeteer source to try to find out the reason, but nothing comes out yet (likely the timeout setting things). @fwhv2042 san, thank you very much for your help. I guess here is the wrong place to discuss. Anyway any help is welcome.

keides2 commented 2 years ago

Excuse me for interrupting. Should this be rolled back to markdown 1.2.1? I tried it, but I got Error: puppeteer.launch() again.