positron icon indicating copy to clipboard operation
positron copied to clipboard

Intercept `webbrowser` open requests for local html files as well as localhost

Open nstrayer opened this issue 1 year ago • 1 comments

Addresses #4118

Hooks into the new 'show-html-file' comm path to display html files opened with the webbrowser python module in the viewer pane.

Previously we overrode the webbrowser opening to forward localhost servers, so this just adds a condition to check for html files and do a similar thing.

Here's an example of it working on a bokeh plot that previously used to open in an external browser: image

Rough edges:

  • Bokeh widget doesn't seem to care about the size of the viewer pane.
  • Not sure if how I am checking for the request being an html file is robust enough. I dont think there's an equivalent URI class in python that we can use, right?

QA Notes

nstrayer avatar Jul 29 '24 20:07 nstrayer

Not sure if how I am checking for the request being an html file is robust enough. I dont think there's an equivalent URI class in python that we can use, right?

You could use urlparse from Python's urllib, which returns a named tuple, and check for the file schema and that path ends with .htm/html, but it does not do any sort of validation, if that is what you consider to be robustness.

isabelizimm avatar Jul 29 '24 21:07 isabelizimm

@seeM , 1 + 2 (done) 3. Not sure, I think it will depend on what we decide about how we differentiate between the two.

nstrayer avatar Jul 30 '24 17:07 nstrayer

@isabelizimm , thanks! Used urlparse in https://github.com/posit-dev/positron/pull/4178/commits/f7a00118f0791d74f5b6540b9b713639cec99a6f

nstrayer avatar Jul 30 '24 17:07 nstrayer