Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when running in Visual Studio Code and maybe other Electron environments #98

Open
enrikb opened this issue Jan 2, 2023 · 0 comments · May be fixed by #101
Open

Fails when running in Visual Studio Code and maybe other Electron environments #98

enrikb opened this issue Jan 2, 2023 · 0 comments · May be fixed by #101

Comments

@enrikb
Copy link

enrikb commented Jan 2, 2023

I'm using unxhr via asciidoctor-kroki and asciidoctor-vscode.
I noticed that XMLHttpRequest does not work in this environment, because the synchronous implementation based on re-executing the running process will fail. It assumes to call node with a helper script as argument.
I'm new to both Electron and Visual Studio Code extensions, but as it seems, you should set the environment variable

ELECTRON_RUN_AS_NODE=1

to make it work with Electron and, in addition, the command line option

--ms-enable-electron-run-as-node

to make Visual Studio Code actually obey above environment variable.

I succesfully verified this within Visual Studio Code using the following patch:

diff -ruN lib/XMLHttpRequest.js ../asciidoctor-vscode/node_modules/asciidoctor-kroki/node_modules/unxhr/lib/XMLHttpRequest.js
--- lib/XMLHttpRequest.js       2023-01-02 15:10:07.171592430 +0100
+++ ../asciidoctor-vscode/node_modules/asciidoctor-kroki/node_modules/unxhr/lib/XMLHttpRequest.js       2023-01-02 15:34:17.592216815 +0100
@@ -520,7 +520,8 @@
       const output = require('child_process').execSync(`"${process.execPath}" "${scriptPath}" \
 --ssl="${ssl}" \
 --encoding="${encoding}" \
---request-options=${JSON.stringify(JSON.stringify(options))}`, { stdio: ['pipe', 'pipe', 'pipe'], input: data, maxBuffer: maxBuffer })
+--request-options=${JSON.stringify(JSON.stringify(options))} \
+--ms-enable-electron-run-as-node`, { stdio: ['pipe', 'pipe', 'pipe'], input: data, maxBuffer: maxBuffer, env: { ELECTRON_RUN_AS_NODE:1 }})
       const result = JSON.parse(output.toString('utf8'))
       if (result.error) {
         throw translateError(result.error, url)

However, I'm not sure if these changes need to be added conditionally and what the conditions would be or how they could be tested.

Cheers,
Enrik

apupier added a commit to apupier/unxhr that referenced this issue Aug 17, 2023
especially targeting VS Code

fixes ggrossetie#98
relates to asciidoctor/asciidoctor-vscode#731

Signed-off-by: Aurélien Pupier <apupier@redhat.com>
@apupier apupier linked a pull request Aug 17, 2023 that will close this issue
apupier added a commit to apupier/unxhr that referenced this issue Aug 17, 2023
especially targeting VS Code

fixes ggrossetie#98
relates to asciidoctor/asciidoctor-vscode#731

Signed-off-by: Aurélien Pupier <apupier@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant