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

Support for page load detection, title display, navigation commands, etc. in the Viewer on Posit Workbench #4276

Open
Tracked by #1617
jmcphers opened this issue Aug 7, 2024 · 0 comments
Labels
area: workbench Issues related to Workbench category.

Comments

@jmcphers
Copy link
Collaborator

jmcphers commented Aug 7, 2024

Currently, the Viewer pane uses Electron APIs to inject a bunch of window message handlers into every page that loads in the Viewer. You can find a writeup of how this works in this PR: #3430

You can find the full set of handlers we inject in this file: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/webview/browser/pre/webview-events.js

Without these handlers, the Viewer pane functionality is significantly impaired. In particular:

  • We don't know when the page is done loading.
  • We can't read the title of the page (for displaying in the Viewer pane).
  • We don't get custom behavior for clicking on links.
  • Events are not forwarded outside the Viewer pane to Positron.
  • Forward/back navigation may not work reliably.

For example, here's where we guess that the load time of the page is 500ms, because we don't have a way to know otherwise.

// Notify the parent window that the window has loaded. This
// is a best-effort guess since we can't see cross-origin
// into the frame.
setTimeout(() => {
window.parent.postMessage({
channel: 'did-load-window',
data: {
title: ''
}
}, '*');
}, 500);

Since we are injecting the handlers using Electron APIs, they are not injected in Posit Workbench. In order to achieve parity with the desktop experience, we need to get them injected somehow (or recreate the functionality in some other way). Some ideas:

  • Ask Posit Workbench to inject the script, since Posit Workbench is already proxying the HTTP requests to the Viewer content.
  • Take advantage of the fact that the cross-domain restriction probably doesn't apply on Workbench -- that is, the content in the Viewer probably has the same authority/security origin as the Positron UI, so try to use script to see directly into the Viewer frame.
  • Create some sort of proxy layer of our own to inject the script.
  • Run away from home and live in the woods.
@jmcphers jmcphers added the area: workbench Issues related to Workbench category. label Aug 7, 2024
@petetronic petetronic added this to the 2024.11.0 Pre-Release milestone Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: workbench Issues related to Workbench category.
Projects
None yet
Development

No branches or pull requests

2 participants