Skip to content

Bringing back (read) access to the webwindow URL using external browsers - #20

Merged
Dev-iL merged 4 commits into
StackOverflowMATLABchat:developfrom
Dev-iL:develop
Aug 5, 2018
Merged

Dev-iL merged 4 commits into
StackOverflowMATLABchat:developfrom
Dev-iL:develop

Conversation

@Dev-iL

@Dev-iL Dev-iL commented Jul 22, 2018

Copy link
Copy Markdown
Member

Description

Title says it all. Also improved getHTML a bit.

Motivation and Context

The ability to display and debug uifigures in a standard web-browser with associated dev tools, seems to have stopped working in R2017b. It's time for it to come back!

How Has This Been Tested?

Tested on R2018a, Windows 10 Pro N x64.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Dev-iL added 2 commits July 22, 2018 15:04
- getHTML now accepts either a webwindow or a UIFigure handle.
- getHTML tries to determine if the webwindow has an associated UIFigure or not, and uses the appropriate technique to get the HTML.
@altmany

altmany commented Jul 22, 2018 •

Copy link
Copy Markdown

Your discovery that changing the hostType property from 'cefclient' to "" enables browser view is an amazing discovery, worthy of a dedicated blog post just by itself!

struct(hUIFig).Controller.ProxyView.PeerNode.setProperty('hostType','""');

@Dev-iL

Dev-iL commented Jul 22, 2018

Copy link
Copy Markdown
Member Author

@altmany I wish I had an explanation for this. Do you have any idea why it works?

I noticed by pure chance that if we put a breakpoint in the webwindow constructor, the URL can be opened in a browser at that stage, but after the figure was fully created that was no longer the case. From there it was relatively easy to find which line made the uifigure inaccessible, and after some trial and error it became clear that the culprit was hostType.

@altmany

altmany commented Jul 22, 2018 •

Copy link
Copy Markdown

I may have been too hasty in my congratulations: when I open a new uifigure and set hostType to "", and then open the URL (struct(struct(struct(struct(hf.UIFigure).Controller).PlatformHost).CEF).URL) in a browser, I still see a blank page... (as I see that you just commented). Strange indeed, but this also means that the hack [currently] is still not enough, maybe there's something else that needs to be done.

@Dev-iL

Dev-iL commented Jul 22, 2018 •

Copy link
Copy Markdown
Member Author

Hmm. Does the example code generate two equally empty browser windows/tabs for you?

Does it work for you if you put a breakpoint at the beginning of the webwindow constructor (e.g. line 132), and open the URL shown in arg?

Update:
@altmany I did some more tests using various browsers (Firefox, Chromium, Vivaldi, and even Edge) - it worked in all of them, as long as the browser is invoked directly by MATLAB using one of

web(hWW.URL,'-browser');
web(struct(struct(struct(hUIFigure).Controller).PlatformHost).CEF.URL,'-browser');

I think it whitelists the browser process somehow.
Moreover, I had to add MATLAB's certificate to the Trusted Root Certificates Store (this is quite easy through IE/Edge on windows). If this poses a security risk, it might be possible to make the webwindow not use a certificate at all (pretty sure I saw something like that while digging through the files).

Demonstration of the link working...

@altmany

altmany commented Jul 22, 2018

Copy link
Copy Markdown

My test is very simple (R2017b Win10):

hFig = uifigure;
hButton = matlab.ui.control.Button('Parent',hFig);
hController = struct(hFig).Controller;
hController.ProxyView.PeerNode.setProperty('hostType','""');
url = struct(struct(struct(hController).PlatformHost).CEF).URL;
web(hFig);

this results in an empty (blank) webpage

@Dev-iL

Dev-iL commented Jul 22, 2018

Copy link
Copy Markdown
Member Author

This is what I get:

image
Maybe it has to do with accepting the certificate...

@altmany

altmany commented Jul 22, 2018 •

Copy link
Copy Markdown

and how exactly do I accept the relevant SSL certificate on localhost?

@altmany

altmany commented Jul 22, 2018

Copy link
Copy Markdown

p,s. importing C:\Program Files\MATLAB\R2017b\sys\certificates\ca\rootcerts.pem to the certificates list in either Internet Options\Content\Certificates or to the Trusted Root Certification Authorities Store on MMC as described here had no apparent effect.

@Dev-iL

Dev-iL commented Jul 22, 2018 •

Copy link
Copy Markdown
Member Author

I believe that the certificate that needs to be accepted is found in prefdir, specifically:

  • fullfile(prefdir, 'thisMatlab.pem')
  • connector.getCertificateLocation()

It should be noted that the steps below are only needed for those unwilling or unable to change the source of some internal MATLAB functions to make the communication channel not require a certificate.

The line we should comment-out is this:

options.Certificate = char(cert);

Found inside the matlab.internal.webwindow constructor (L251@R2017b; L278@R2018a).


I'm going to show how to accept the required certificate in Windows using IE/Edge. This requires no administrative privileges on the system. This technique was tested on Windows 7 and R2017b, and assumes that Chrome Version 67.0.3396.99 (Official Build) (64-bit) is the default browser.

On Chrome , when we first open a UIFigure URL we get the following warning:
image

Upon clicking Advanced > Proceed to localhost (unsafe) we get to a blank window, which has recurring errors in the console (Inspect > Console):

image

If we open this using IE/Edge we get a similar screen:
image

From here we can click Continue to this website (not recommended). After which the address bar changes to:
image

Note that the "Certificate error" is a clickable button, so we do the following:
image

Afterwards, we need to create a new UIFigure, unlock it, and invoke the external browser using web(URL,'-browser') (the easiest thing at this stage is to run the example code).

Now, what we see in Chrome are the contents of our UIFigure, with no errors in the console:
image

Dev-iL added 2 commits July 24, 2018 18:20
Note: it was only tested with an actual MATLAB installation on Windows!
@Dev-iL

Dev-iL commented Aug 5, 2018

Copy link
Copy Markdown
Member Author

Merging this seeing how there weren't any further "objections" :)

@Dev-iL
Dev-iL merged commit 80b7868 into StackOverflowMATLABchat:develop Aug 5, 2018
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