Commit 80290c21 authored by Robert Knight's avatar Robert Knight

Show a clearer error if `window.open` call fails

If opening the login popup window using `window.open` fails or succeeds
but fails to return a `Window` reference to the caller then show a more
helpful error message.

There are various rare scenarios (browser bugs, browser extensions)
which might cause this to happen. There is not a whole lot we can do to
recover, but at least we can show a better error message.
parent 527aed43
......@@ -255,10 +255,16 @@ export default class OAuthClient {
})
.replace(/&/g, ',');
return /** @type {Window} */ ($window.open(
const authWindow = $window.open(
'about:blank',
'Log in to Hypothesis',
authWindowSettings
));
);
if (!authWindow) {
throw new Error('Failed to open login window');
}
return authWindow;
}
}
......@@ -183,7 +183,7 @@ describe('sidebar/util/oauth-client', () => {
});
});
describe('.openAuthPopupWindow', () => {
describe('#openAuthPopupWindow', () => {
it('opens a popup window', () => {
const fakeWindow = new FakeWindow();
const popupWindow = OAuthClient.openAuthPopupWindow(fakeWindow);
......@@ -195,6 +195,15 @@ describe('sidebar/util/oauth-client', () => {
'height=430,left=274.5,top=169,width=475'
);
});
it('throws error if popup cannot be opened', () => {
const fakeWindow = new FakeWindow();
fakeWindow.open = sinon.stub().returns(null);
assert.throws(() => {
OAuthClient.openAuthPopupWindow(fakeWindow);
}, 'Failed to open login window');
});
});
describe('#authorize', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment