SafeExamBrowser / seb-mac

Safe Exam Browser for macOS and iOS
https://www.safeexambrowser.org/macosx
101 stars 41 forks source link

Open new window/tab with JavaScript fails #230

Closed uhensler closed 2 years ago

uhensler commented 2 years ago

When opening a new window/tab with JavaScript an exception occurs because the JavaScript variable targetWindow is always null.

var targetWindow = window.open("","_blank");
...
targetWindow.location.href = '<the real url>';

In the GUI this leads to a popup with the message "Quit Safe Exam Browser: Are you sure you want to quit Safe Exam Browser?".

danschlet commented 2 years ago

Can you provide a test page where I can reproduce this? I guess you mean a JavaScript exception which occurs?

The “Quit Safe Exam Browser” alert is displayed when closing the main (initial) browser window, maybe your JS code attempts that? SEB must distinguish the main, initial window, in which the exam is loaded with the Start URL setting and all additional windows. It is therefore not allowed to close that initial window, otherwise the (exam) session is closed and SEB quit.

uhensler commented 2 years ago

Test page will be sent by private email.

danschlet commented 2 years ago

window.open() in SEB for macOS/iOS currently doesn't return the window object when the modern WebView is used. It might work with the classic webView on Mac, at least in all the years no one complained about it. Or maybe people just refrained from using JS to open new windows.

If you need the window object, your website code needs to get it when the new page is loaded in the new window. SEB also doesn't support changing the browser window size or properties, browser windows are always created according to settings in Preferences/Browser ("New browser window size and position").

SEB is a kiosk browser, so it has some restrictions compared to ordinary web browsers. Web applications wanting to run in the kiosk environment might need some adjustments.

danschlet commented 2 years ago

In SEB 3.1 there is actually a crash happening, which is already fixed in latest development builds. This doesn't change the window object issue though.

uhensler commented 2 years ago

If you need the window object, your website code needs to get it when the new page is loaded in the new window.

This does not work for us. We need the window to set the URL and load the page.

danschlet commented 2 years ago

Can't you set the URL in the window.open command?

Without knowing your use case, there are usually several ways how to reach a goal or workarounds. I will try to make this work, but I can't guess how complicated it will be (didn't find anything in a quick search). I checked and there's also no window object returned when using window.open() in the classic WebView since SEB 3.0. It worked in SEB <= 2.3.2, so the implementation to be able to use both WebView types broke this.

That means that it probably should be fairly easily possible to make it work also in the modern WebView and fix it in the old one, I'll try to add the fix in SEB 3.1.1 (if too time consuming in 3.2).

uhensler commented 2 years ago

Can't you set the URL in the window.open command?

We can't because we do not know the URL when we call window.open. There is a lot of logic in ....

This issue is exactly the same as the fixed issue for SEB for windows. So, we are confident you can fix this in SEB for macOS as well.

danschlet commented 2 years ago

This is now fixed in SEB 3.1.1rc (release candidate, please test).

I also investigated the same fix for the iOS/iPadOS version of SEB, but the according WKWebView API seems to be broken on iOS. I will file a bug with Apple, without them fixing it I don't think I can do anything to make it work on iOS/iPadOS.