Oidc-client: how to use signoutPopup method properly - javascript

I'm wondering how to logout properly through the oidc-client UserManager signoutPopup method, without throwing an error when the user closes the popup window?
I'm calling UserManager's signoutPopup method and a popup window opens telling me that I've been logged out and I'm also presented with a link back to the application. Up until now everything works as expected.
Now, if I follow the above link, the application is loaded into the same window. Regardless whether I follow the link first, or close the window immediately there's an error
'Popup window closed'.
When the popup window is opened UserManager starts a timer that throws the above error if the window is closed before being cleaned up. I'm guessing that I'm supposed to clean it up somehow. Maybe, I'm just supposed to catch the error.
Does anybody know how logout with the signoutPopup method is supposed to work? I haven't been able to find any documentation or examples regarding this.
I'm using oidc-client 1.2.2, Angular 2 and IdentityServer 3.

Related

How to prevent document from creating new popup windows onclick event of user using javascript

In my wordpress site, some hacker has embedded a script into it somewhere.
The problem I'm having now is, whenever the site is opened, the first time a user clicks anywhere on it, a spam popup appears, due to the hacker's script.
Is there any way I can prevent the popup window from being created with Javascript?
If I can't prevent it, is there any way that I can close the popup using JS? Unfortunately, since the other script is creating it, I don't have a reference to the opened window. I've seen other scripts calling .close() on an opened window, but I don't have a reference to the new window, so I don't know how to close it.
Here's my site.
The popup on your site is opened by something calling window.open. You can prevent it by assigning something else to window.open and running your script before the other script does:
window.open = () => undefined;
(This does work, if I run this code on your site before your site's Javascript runs, no windows get opened)
It's not uncommon for a client to want to implement this, but if you're the server, it'd be better to fix the server to remove the malicious code, rather than try to patch around it.

React popup window.open null opener when triggered from useEffects first render

I'm trying to trigger a popup on initial page load (based on certain conditions). The purpose being for oauth authentication. I have everything working through a button click, but for some reason when trying to open the popup using a useEffect, I run into the issue where the window.opener is null and therefore cannot callback.
I have made a minimal demo here outlining the issue. Immediately upon loading, it should attempt to open a popup automatically. If you allow it, and then run window.opener in the console of the popup, you'll see that it is null
However, pressing on either button (direct or through the same use useEffect via a state dependency) the window will open again and the opener will no longer be null.
https://codesandbox.io/s/condescending-shannon-t0xjo
Perhaps you browser is blocking popups as it is not an user initialised event?

Close window from browser history

I am working on a web application where I am using JavaScript for the client side scripting. Now my requirement is to close all the opened window which were opened through window.showModalDialog().
For this, I read the history of the browser using window.history.length, but I do not know how to close each window. This works well for window.open(), but not for window.showModalDialog().
Could you please guide me to move forward?
You can close the opened window as follows:
To Open:
var window1=window.open("http://somedomain.com");
var window2=window.open("http://someotherdomain.com");
To Close
window1.close();
window2.close();
But be sure you call window1.close() and so on.. on the same script where you opened it.
You should not be using window.showModalDialog. Firefox has deprecated it, and Chrome has removed it. Also take a look at window.showModalDialog: What It is and Why You Should Never Use It.
The idea of showModalDialog is that all scripts are paused while the modal window is open. Thus, using window.close doesn't work, since as long as the window is open, no more scripts are being executed.
One possibility is to have JavaScript in the modal dialog so that is closes itself. You will not be able to close it from outside.

Using funcunit to test a popup window

I am using FuncUnit to test a small application I wrote. I have a button that will open a popup window (using the JavaScript function window.open(...)). I can get FuncUnit to press the button and open the pop up window,but I'm not sure how to proceed in order to get a handle on the popup window and do further testing.
Unfortunately, I cannot change any of the code in the pop up,
Thank you,
Matt
open returns a reference to the created window's window object. So you can simply use that to access anything in the window. Not sure if you can verify that it has finished loading if you can't modify the popup. Also note that both windows must be on the same domain in order for you to access it.

Open new browser windows in JavaScript without making it active

I have some JavaScript that makes an AJAX call and, if the call fails, opens a new windows (tab in Firefox) and displays the response from the server in that window. This is very convenient for debugging, because the error is typically from Pylons, so it's a full HTML page.
The only problem is that the new tab becomes the active tab, which would totally confuse a regular user. Is there any way to open the tab/window, but not make it active, ie. keep the current active window?
My code currently looks like this:
errorWindow = window.open("", "TCerrorWindow")
if (errorWindow)
errorWindow.document.write(xhr.responseText);
You can call errorWindow.blur(); window.focus(); after, forcing the browser to return focus to the previous window.
The effect you're trying to achieve is commonly called a pop-under window.
AFAIK this is not possible, as a security measure against pop-under windows. For debugging purposes you could
use Firebug (with a handy console, where you can output your own log messages from the code)
create a debug layer (div) on your page, where you output error messages in case an error happens

Categories