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

[code] support live preview of local files #3831

Open
kevinadhiguna opened this issue Apr 8, 2021 · 36 comments
Open

[code] support live preview of local files #3831

kevinadhiguna opened this issue Apr 8, 2021 · 36 comments
Labels
editor: code (browser) meta: never-stale This issue can never become stale type: feature request New feature or request

Comments

@kevinadhiguna
Copy link

kevinadhiguna commented Apr 8, 2021

Bug description

Unable to see HTML file and faced a HTTP 400 Bad Request issue. Instead, I saw a text saying : Web Sockets Request was expected.

Steps to reproduce

  1. Create index.html and index.ts file.

index.html :
image

index.ts :
image

  1. Compile index.ts with yarn tsc index.ts and produce an index.js file.

index.js :
image

  1. Create an <h1>Hello</h1> and connect it to index.js.
  2. Open a new tab to access <PORT>-<Gitpod Workspace URL>.
  3. See a text saying : Web Sockets Request was expected.

image

Expected behavior

Display an HTML file and run Javascript in console.

@kevinadhiguna kevinadhiguna changed the title [Error] WebSockets Request was expected, also faced a CORS issue [Error] WebSockets Request was expected, also faced HTTP 400 Bad Request when running an HTML file Apr 8, 2021
@akosyakov
Copy link
Member

Are you sure that you are using the correct port? The server tells you that it exposes web socket connection, not pure http.

@akosyakov akosyakov added meta: 🤔 reporter-feedback-needed cannot process further since we need more info from the reporter editor: code (browser) labels Apr 8, 2021
@akosyakov
Copy link
Member

Could you share the repo please? From the description is not clear which server you are running.

@kevinadhiguna
Copy link
Author

Could you share the repo please? From the description is not clear which server you are running.

Sure, here is the repo : https://github.com/kevinadhiguna/typescript

@kevinadhiguna
Copy link
Author

I just ran it, it said it runs on port 42139 :

image

Then I clicked the Open Browser icon :

Screenshot from 2021-04-08 18-08-16

Again, it showed me WebSockets request was expected :

image

@akosyakov
Copy link
Member

This port is a debug port for Gitpod Code Server. It does not have anythign to do with index.html

Are you trying to preview index.html?

@kevinadhiguna
Copy link
Author

This port is a debug port for Gitpod Code Server. It does not have anythign to do with index.html

Are you trying to preview index.html?

Yes, I am. Sorry I am confused how to preview the HTML file. The docs in Gitpod shows how to do it in Theia but I am a bit confused as I usually drag ad drop an HTML file in local machine to preview it. Do you mind telling me how to preview HTML in a new tab from Gitpod ?

@akosyakov
Copy link
Member

Hm, VS Code does not support this feature by default, but you can install additional extensions like: https://open-vsx.org/extension/ritwickdey/LiveServer Could you give it a try?

@akosyakov akosyakov added type: feature request New feature or request and removed meta: 🤔 reporter-feedback-needed cannot process further since we need more info from the reporter labels Apr 8, 2021
@akosyakov akosyakov changed the title [Error] WebSockets Request was expected, also faced HTTP 400 Bad Request when running an HTML file [code] support previewing local files with the simple browser Apr 8, 2021
@akosyakov akosyakov added this to the [backlog] April 2021 milestone Apr 8, 2021
@kevinadhiguna
Copy link
Author

Sure, I just installed the Live Server extension in VScode in Gitpod.

Next, I right-clicked index.html and opened it with Live Server :

Screenshot from 2021-04-08 18-36-37

The result was :

image

A couple of questions please :

  • HTTP 404 indicates that favicon.ico was not found, or another error ?
  • Why Firefox could not establish connection to the server ? Is there anything wrong ?

@akosyakov
Copy link
Member

HTTP 404 indicates that favicon.ico was not found, or another error ?

correct

Why Firefox could not establish connection to the server ? Is there anything wrong ?

that's probably related to how we handle ws connection

@akosyakov
Copy link
Member

I tried in both Chrome Version 89.0.4389.114 (Official Build) (x86_64) and FireFox 87.0 (64-bit) and it worked well. I don't see any errors in FF:
Screenshot 2021-04-08 at 13 58 22

Are you sure that you are using in latest FF?

@kevinadhiguna
Copy link
Author

HTTP 404 indicates that favicon.ico was not found, or another error ?

correct

Why Firefox could not establish connection to the server ? Is there anything wrong ?

that's probably related to how we handle ws connection

Thank you very much, that was so helpful.

@kevinadhiguna
Copy link
Author

Yes I am using the latest Firefox version 87.0 (64-bit)

image

I once stopped the workspace and the error vanished. However, if I start it again, somehow it appears again in the console..

@kevinadhiguna
Copy link
Author

Anyway, the Firefox unable to establish connection is not a major issue here IMO. Many thanks for the prompt reply, it helped a beginner like me a lot !

@akosyakov
Copy link
Member

please upvote here to implement live preview in VS Code: microsoft/vscode#12080 You can also follow this thread for other solutions (VS Code extensions).

@akosyakov akosyakov changed the title [code] support previewing local files with the simple browser [code] support live preview of local files Apr 9, 2021
@kevinadhiguna
Copy link
Author

please upvote here to implement live preview in VS Code: microsoft/vscode#12080 You can also follow this thread for other solutions (VS Code extensions).

Upvoted, thanks

@akosyakov akosyakov modified the milestones: April 2021, May 2021 (backlog) Apr 13, 2021
@yandeu
Copy link

yandeu commented Apr 13, 2021

A couple of questions please :

  • HTTP 404 indicates that favicon.ico was not found, or another error ?
  • Why Firefox could not establish connection to the server ? Is there anything wrong ?

Would it be possible for you to test this with Five Server?

@kevinadhiguna
Copy link
Author

A couple of questions please :

  • HTTP 404 indicates that favicon.ico was not found, or another error ?
  • Why Firefox could not establish connection to the server ? Is there anything wrong ?

Would it be possible for you to test this with Five Server?

How may I install Five Server in Gitpod ? @yandeu

image

@yandeu
Copy link

yandeu commented Apr 14, 2021

How may I install Five Server in Gitpod ?

I have just added it.


Also, I found a bug in Live Server and Five Server that prevents auto-reload on an index page. If you want to use auto-reload, access your index file with /index.html.

But everything else (instant update, highlight, auto navigation) works fine.

I will publish an update to Five Server tomorrow.

@kevinadhiguna
Copy link
Author

Thank you @yandeu , I was able to install Five Server extension.

image

However, I encountered some issues regarding connection.
This is how it looks in Firefox :

image

Terminal in Gitpod in FIrefox :

image

This is how it looks in Chrome :

image

Terminal in Gitpod in Chrome :

image

This HTTP 404 indicates that favicon.ico was not found, or another error ? was replaced with Five Server's favicon.ico, wasn't it ? As it no longer occurred.
Meanwhile, do you have a clue on this issue : Why Firefox could not establish connection to the server ? Is there anything wrong ?

Environment
Firefox : Version 87.0 (64-bit)
Chrome : Version 89.0.4389.114 (Official Build) (64-bit)
OS : Ubuntu Focal Fossa 20.04.2 LTS

@kevinadhiguna
Copy link
Author

In firefox, I had to click refresh button to get rid of the error :

image

Nevertheless, the Firefox can't establish connection to the server .. error happened again after a few seconds.

The same goes to Chrome :
image

@yandeu
Copy link

yandeu commented Apr 14, 2021

Five Server's favicon.ico, wasn't it ?

Yes 😄 (see yandeu/five-server@5564c40)

Why Firefox could not establish connection to the server

Yes, I will try to fix that today. In the meanwhile try to rename your index.html to something else like website.html.


Also, there is a small bug when reloading css. Will fix that as well 👍

@yandeu
Copy link

yandeu commented Apr 14, 2021

@kevinadhiguna I have fixed everything. Just had no time to release it today :/

@yandeu
Copy link

yandeu commented Apr 15, 2021

Five Server v0.0.25 is now available on gitpod and it works very very well :)

@kevinadhiguna
Copy link
Author

Cool @yandeu , it worked like magic ! Thanks

image

@yandeu
Copy link

yandeu commented Apr 17, 2021

You're welcome 🙂

Also, there are new cool features in development.

Currently working on a sort of "Hot Module Replacement" feature. Means, instant update while keeping the state (DOM) previously manipulated by JavaScript 👍🏻

@akosyakov
Copy link
Member

@yandeu Does it support preview of PDF files too? In Theia we used to have special handling for pdfs: https://github.com/eclipse-theia/theia/blob/96930a2edcc4c706d41ab8486500de7979d01283/packages/mini-browser/src/browser/mini-browser-content.ts#L581-L593 Maybe you can get inspired from that and add PDf support for Five Server too? We have such questions in the community: https://community.gitpod.io/t/latex-pdf-viewer/3365

@yandeu
Copy link

yandeu commented Apr 21, 2021

I have not implemented anything special for PDFs yet. I guess if you try to preview it, it will display "File is too big for a preview"? I haven't tried it yet. Have you tried it? What does it show?

Five Server allows for middlewares, similar to an express app. So I guess it would be possible to embed a PDF preview.

Feel free to open a new Feature Request Issue on yandeu/five-server (not yandeu/five-server-vscode).

@akosyakov
Copy link
Member

@yandeu here you go yandeu/five-server-vscode#1

@akosyakov
Copy link
Member

@yandeu I tried the latest extension and it gives me:
Screenshot 2021-04-23 at 08 44 50

From this repo: https://github.com/joejcollins/latex Maybe some CSP is misconfigured for iframe in remote context, not sure?

@yandeu
Copy link

yandeu commented Apr 23, 2021

Yes, I think the CSP policy of the WebView is blocking iFrames.
But it works fine if you try to preview it in the browser :)

@akosyakov
Copy link
Member

Yes, I think the CSP policy of the WebView is blocking iFrames.

It is strange though, frame-src is set to * for the preview extension. Maybe some attributes or policies are missing on level of five server iframe?

@csweichel csweichel removed this from the May 2021 (backlog) milestone May 6, 2021
@mfouesneau
Copy link

I'm getting the same issue for the PDF viewer. Any updates? Could there be information if this issue shows up with vs and not theia maybe?

@yandeu
Copy link

yandeu commented May 18, 2021

@mfouesneau @akosyakov Please help to debug the PDF preview feature on https://github.com/yandeu/preview-pdf-test

@mfouesneau
Copy link

mfouesneau commented May 18, 2021

Sure. How can we provide help?
The main issue remains also on the pdf preview tool: "Requests to the server have been blocked by an extension." because of the security issues.
One main problem is that this extension is not linked with the usual tools (eg. Latex workshop) which reduces the features.

@yandeu
Copy link

yandeu commented May 18, 2021

It looks like the "Simple Browser" preview does not support loading PDFs.

Therefore, Five Server will only show PDF preview in the browser.

I tried Office Viewer which seems to show a preview for PDFs.

@stale
Copy link

stale bot commented Aug 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label Aug 16, 2021
@akosyakov akosyakov added the meta: never-stale This issue can never become stale label Aug 17, 2021
@stale stale bot removed the meta: stale This issue/PR is stale and will be closed soon label Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor: code (browser) meta: never-stale This issue can never become stale type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants