Builtin web browser

I believe there is a web browser built into Slicer. Is it possible to invoke a URL from a python interactor and popup a window? I want to test if a user can interactively authenticate to a data repository we want to support.

There is a built-in web browser, so that’s one option. It could be also interesting if you can authenticate using Python libraries (e.g., oauth2). What kind of authentication that site uses?

To be perfectly honest I do not know what they are currently using. I believe, plan on changing to oauth2 and let users create access tokens to be used with API, but that’s a little ways from now. We also need to render some items from their webpage within Slicer (browse and search items, similar to datastore).

Can you point me to documentation about internal web browser?

In Slicer 4.10 you can do the following from python:

qt.QDesktopServices.openUrl(qt.QUrl('http://slicer.org'))

to open your desktop browser at an arbitrary URL, but it’s not connected back to Slicer so there’s no easy way to get the authorization token back from the browser for use in web requests (you could do some kind of cut-and-paste or other manual method).

There is also a built-in browser based on QWebEngine that is used in the ExtensionManager and DataStore.

w = slicer.qSlicerWebWidget()
w.webView().url = qt.QUrl('http://slicer.org')
w.show()

The python wrapping is not complete (can’t access javascript contents, such as the token, via python but should be able to via C++.

Search for the Qt docs on QtWebEngine fore more details about what you can do with it.

Thanks @pieper. I did manage to login through the built-in browser. I tried to download a file, and as far as I can tell it did. But any idea where it may have ended up? It couldn’t locate it in the slicer temp directory.

I’m not sure - Qt transitioned to a new web architecture and some things aren’t as easy to use as they used to be. For example some classes are not exposed in PythonQt and that makes it a bit harder to test. Hopefully it won’t be too much work to enable but I haven’t looked into the details.

My hope has been to make it pretty seamless to go between the built-in browser and the slicer/python world in order to facilitate the kinds of interactions you are describing, but the web infrastructure switch set that back a bit. I think it’ll still be possible.