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

Add browser WebView command buttons #494

Merged
merged 8 commits into from
Dec 13, 2020

Conversation

renkun-ken
Copy link
Member

@renkun-ken renkun-ken commented Dec 12, 2020

What problem did you solve?

This PR adds the following buttons to WebViews created by browser.

  • Refresh: useful If the browser WebView is loaded too early (e.g. Significantly delay of auto port forwarding under remote development microsoft/vscode#112297) or not properly loaded, or the user wants to reload the page for some reason.
  • Open in external browser: useful if the WebView cannot show the page properly (most likely due to some WebView limitations).
  • Find: find text in WebView. This is identical to the "R Help Panel: Find in Topic" command. Therefore I rename this command so that it sounds more general.

Also, this PR uses vscode.env.asExternalUri introduced at https://code.visualstudio.com/api/advanced-topics/remote-extensions#forwarding-localhost instead of port mapping. Now the port forwarding should work smoothly under remote development when a browser WebView is created without relying on explicit port mapping (currently not working, see microsoft/vscode#102449) and auto port forwarding (currently not working smoothly, see microsoft/vscode#112297).

(If you have)Screenshot

image

(If you do not have screenshot) How can I check this pull request?

  1. Create a R terminal with session watcher attached.
  2. Run shiny::runExample("01_hello") and a WebView is created
  3. Focus on the WebView, and the two commands should appear on the right side of the tab.
  4. Click "Refresh", and the WebView is reloaded.
  5. Click "Open in external browser", and the user web browser is launched to show the web page.
  6. Click "Find", and the find widget should work.

"Open in external browser" should also work under remote development as it will automatically setup the port forwarding from remote to local. To test, just repeat the above steps under remote development and the behavior should be exactly the same.

@renkun-ken renkun-ken requested a review from Ikuyadeu December 13, 2020 05:57
@ManuelHentschel
Copy link
Member

Works nicely, thanks!

I added a small change that hides the help-panel controls after closing the help panel (this was previously done only on changeViewState events).

Would it be possible/feasible to implement the back and forward buttons for general webviews? E.g. after calling utils:::print.help_files_with_topic(help('mean')) and clicking some hyperlink it would be nice to be able to go back to the initial help page. There seems to be some mechanism to implement this for iframes, though I haven't tried using this in vscode yet.

@renkun-ken
Copy link
Member Author

Thanks for the review!

Would it be possible/feasible to implement the back and forward buttons for general webviews?

The browser WebView is mainly used to show reactive content (e.g. shiny apps, httpgd graphics) rather than general purpose web browsing. I suspect if it is really useful to be able to go backward/forward on the page since most reactive content is not designed to work with such navigation operations.

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 this pull request may close these issues.

2 participants