mlapptools icon indicating copy to clipboard operation
mlapptools copied to clipboard

unlockUIFig functionality discontinued

Open thewingit opened this issue 7 years ago • 9 comments

Problem Description

Testing the unlockUIFig from the provided example gives me following MATLAB exception:

Undefined function or variable 'wasImported'.

Error in mlapptools/unlockUIFig/checkCert (line 412)
            if wasImported

Error in mlapptools.unlockUIFig (line 351)
            assert(checkCert(), 'Certificate not imported; cannot proceed.');

I think the problem was introduced in 6e12b32f98a3426a0c7d3488311a54bee889893d and it occurs if one executes unlockUIFig after the certificate has been installed.

I fixed the issue by defining wasImported outside the if clause, but I can't see the figure anyways on my browser. I tried both Chrome and Firefox. Both give me the warning of invalid certificate and I have to add a security exception, but that's normal I think.

Steps to Reproduce the Problem

To reproduce the issue, simply try to run the code from the provided example.

Specifications

  • MATLAB Release: R2017b
  • Operating System: Windows 10 Enterprise
  • mlapptools version (or commit link/hash): 2dcedfd03214843192c64cb3ac5b268e1aaa0c7a

thewingit avatar Aug 28 '18 08:08 thewingit

Hi @thewingit,

This issue was already fixed on my own ("development") fork, but hasn't been merged yet.

Feel free to try that version out if you like!

Dev-iL avatar Aug 28 '18 09:08 Dev-iL

Hi @Dev-iL ,

Thanks for the quick reply. I'll try the forked one out.

EDIT: I tried the forked version out. The problem with the uninitialized variable is gone, however the browser still won't display the UI content, it shows me a blank page.

By inspecting the browser's dev tools, it seems that I have problems with some JS that is trying to connect with the local server:

Source map error: request failed with status 404
Resource URL: https://localhost:31515/toolbox/matlab/uitools/uifigureappjs/release/gbtclient/gbtclient.js
Source Map URL: gbtclient.js.map[Learn More]
Source map error: request failed with status 404
Resource URL: https://localhost:31515/toolbox/matlab/uitools/uifigureappjs/release/dojo/dojo.js
Source Map URL: dojo.js.map[Learn More]
Source map error: request failed with status 404
Resource URL: https://localhost:31515/toolbox/matlab/uitools/uifigureappjs/release/gbtclient/browsercheck.js
Source Map URL: browsercheck.js.map[Learn More]

It seems from the error log that the MessageService tries to connect 30 times and then fails completely.

Anyway, it might be related to my system.

thewingit avatar Aug 28 '18 09:08 thewingit

@thewingit Unfortunately I haven't seen your edit earlier since I wasn't notified about it (unlike when you post a new reply).

What you describe is the same issue that was discussed at length in the last PR. While I have provided detailed steps for, it didn't seem to help Yair.

I run into this issue from time to time myself, and the way I solve it is by running the figure code twice - the first time around we get a blank page, but the 2nd time it works. Note that it is important NOT TO CLOSE the browser window in which the non-working 1st tab was created. After the 2nd (working) tab is opened, the 1st can be closed.

If this doesn't work for you, feel free to contact me in chat, and I'll try to assist you.

Dev-iL avatar Aug 28 '18 11:08 Dev-iL

Hi @Dev-iL ,

thank you for your response. I tried what you mentioned but it doesn't seem to work, either. I tried also to comment out the certificate line in the internal webwindow source code, but this seems to break MATLAB somehow (the figure is not displayed at all and I got stuck while exiting).

BTW i get the same problem you posted in the PR's comments.

To me it seems pretty much an authentication problem, as the local server refuses to let the browser connect to the messaging service.

thewingit avatar Aug 28 '18 11:08 thewingit

Unfortunately this functionality is not very stable. Although I got it working on several different systems and different MATLAB releases (some were clean MATLAB installs), other users of the tool seem to have difficulties. I'm not sure what exactly I'm doing differently, but here are the steps I take:

  • Use Firefox (in my case 62.0b20 (64-bit) ).
  • Run the part of the code that does the unlocking and the opening of the browser (example, or yours) without debugging, i.e. in one go.
  • Do not to attempt to unlock the figure, then manually get the webwindow URL and put it in a browser of your choice1 - it is important that MATLAB invokes the default system browser itself (i.e. using web(hWW.URL,'-browser')). Moreover, since MATLAB invokes the default browser, one must change the default if they want to use another browser for this.
  • If the tab shows a blank page with connection errors in the console, run the figure creation code once more. As I mentioned, it is important NOT TO CLOSE the browser window in which the non-working 1st tab was created. Only after the 2nd tab is opened (which should be working), can the 1st tab be closed.

What is your default browser? When you tried it with Firefox, did you import the certificate using the dedicated Firefox dialogs, or did you rely on the OS import? For Firefox, different steps are required (they are mentioned inside the subfunction checkCert).


1 Although this used to work in older releases, this method is completely invalid as of R2017b.

Dev-iL avatar Aug 28 '18 12:08 Dev-iL

Hi @Dev-iL ,

sorry I'm responding that late. I didn't find the time to work on this further.

I tried your steps in Google Chrome, Mozilla Firefox and Microsoft Edge browsers by setting them as default browser and by calling them from MATLAB directly using your example ( web(hWW.URL,'-browser'); ), respectively. It seems that none of them work.

Anyways I want to thank you for your support. As soon as I have time to work on this, I will let you know.

thewingit avatar Aug 31 '18 07:08 thewingit

@thewingit I empathize, I was having a frustrating time with this same issue at first.

When we 'unlock' the figure for viewing in an external browser we are essentially tell MATLAB that the host is undefined, which should bypass a browser-checking script MATLAB has written into the uifigure. For whatever reason, this check will fail sometimes if the channel being opened to browser has some 'not-ready' status.

What I have found works for me on Chrome Version 68.0.3440.106 (Official Build) (64-bit) (Windows 10 64bit) with MATLAB 2018a is if I open chrome before launching MATLAB, unlockUIFig from @Dev-iL 's branch works every time. At one point though, it suddenly stopped working and I had to manually reinstall the certificate through chrome's certificate manager. I could not ascertain exactly why this happened or why reinstalling the certificate helped.

Khlick avatar Aug 31 '18 12:08 Khlick

Hey @Khlick, thanks for the feedback! I will give it a try as soon as possible.

thewingit avatar Aug 31 '18 13:08 thewingit

According to this comment:

... you can turn on debugging by running:

matlab.internal.webwindow('http://example.com', 'DebugPort', 4040)

before any other App, or kill all MatlabWindow applications (from task manager) before the command. Then go with Chrome to http://localhost:4040/.

... so this might be another thing to try.

Dev-iL avatar Mar 31 '23 09:03 Dev-iL