-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo doc --open
should start a web server to avoid restrictions with file-based browsing
#4966
Comments
This has historically been controversial. I'm pro, but there are a lot of people against. |
What are the con arguments? |
I've just installed Vimium on Firefox, it works great. So maybe install Firefox :). |
As far as I understand, it's browser or vimium problem. But if we do this, it makes sense to use separate key, for example: |
Yeah it is a Chrome bug. In general, Chrome cares only very little about the But why should firefox users being made suffer? Firefox works great, but http://localhost is far more inconvenient than file protocol based services. |
having a built-in server would be really useful for those that usually work inside a ssh session/vm and use a browser outside the shell session. |
Why trying to squash the universe inside one tool? Let cargo doc generate documentation, let another tool host it. |
This gist has some one-liners for spinning up a web server for static content: eg:
will spin up an http server on 0.0.0.0:8000 (potentially world accessible; take appropriate care!). It's not as convenient as While I'm on the fence about building this support directly into cargo, it would be nice if there was an easy way to do this, or that the docs/help pushed folks towards a couple of nice recipes to help with this use case. |
I'm hacking together a |
just pushed https://crates.io/crates/cargo-docserver, hopefully that's useful for someone besides me |
@qmx it works, thanks! |
Probably if it is an edge case scenario, you can use https://www.npmjs.com/package/serve to serve your docs to a localhost and then open that in chrome(ium). This is much simpler solution than building a server inside cargo itself. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
No I haven't. What I meant with the suggestion was that cargo is not meant to be a server. Including an http server just to view docs on localhost doesn't make much sense when there are libraries such as cargo-docserver. I was just suggesting a simple solution in terms of the time it would take for someone to use it. Granted it is simple only for those who already have node installed, but it is a simple solution nonetheless. |
cargo doc --open
should start a web server to enable keyboard accessibilitycargo doc --open
should start a web server to avoid restrictions with file-based browsing
Web-browser are getting more strict regarding file access. The access/import of files from dynamically created path strings will be blocked when using the file-protocol. Rustdoc's deep hierarchical folder structure (sub-folder per mod) requires dynamic import paths for the generalized helper-scripts in folder "static.files/" Short StoryMy proposal is to use a flattened rustdoc HTML file structure instead, that will permit to reference the helper scripts using static paths always, such as "../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2" (one level up). Long StoryThe rustdoc is organized in folders hierarchically, within each document the relative location of the folder static.files/ is derived reading the following attribute
Due to this fact the import paths for further scripts/files are constructed dynamically using rootPath as prefix. When using the file-protocol to read the rustdoc, these dynamic imports will be blocked by the browser, see CORS error message of Chrome below.
This means, when using the file-protocol certain styles and features can not be loaded form folder static.files and the rustdocs will appear differently compared to using the http-protocol. ProposalThe solution might be to turn to static import paths. This could be achieved by flattening the folder structure of the rustdocs, using a file set for each crate of folder depth=1 only, so that a static string could be use for the import paths always.
Using static import paths, the CORS issue would no longer exist and the file-protocol could be used the same way as http-protocol. ( AFAICS) PS: other rustdocs add-ons such as aquamarine must evaluate rootPath value as well, right now. Using a flattened folder structure (depth=1), the integration of these tools would be simplified. |
This change would be very useful to me as I run Firefox in a Flatpak container which only has access to |
Thought I would add in a real-world use case issue that I'm experiencing and am sure other people are running into these days as well: For those that use VSCode with Devcontainers, running The solution for this would be an HTTP server that serves the files in a basic manner. In addition to the above, it looks as though |
Hi @qmx, may I ask why this repo is archived? |
|
Running
cargo doc --open
currently opens the file in the browser with thefile://
protocol.In this protocol, web extensions like Vimium don't have access to the page and can't provide keyboard shortcuts.
It would be nice if running
cargo doc --open
would start a web server like http then navigate to the generated index file. I've tested that and Vimium works normally. Thank you!The text was updated successfully, but these errors were encountered: