Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OAuth popup being blocked by pop-up blocker in Firefox and IE #537

Merged
merged 2 commits into from
Sep 11, 2017

Conversation

robertknight
Copy link
Member

When the user clicked the "Log in" link, the URL of the
"oauth.authorize" endpoint was fetched via an async Promise-returning
method before the window.open call was made. This meant that the
window.open call did not happen in the turn of the event loop that was
triggered by the user action and so Firefox & IE's popup blockers deemed
the call to have happened outside the context of a user gesture and
prevented the window being opened.

Chrome, Safari & Edge have different heuristics and did not block the
popup before.

Fix the issue by opening the window directly when the user clicks on the
"Log in" button, at a dummy URL ("about:blank"), and then changing the
window's location once the authorization endpoint URL has been fetched.

Fixes #534

Testing note: OAuth login does not yet work in IE for other reasons which will be fixed separately, so for the moment, just test following the steps in #534.

When the user clicked the "Log in" link, the URL of the
"oauth.authorize" endpoint was fetched via an async Promise-returning
method before the `window.open` call was made. This meant that the
`window.open` call did not happen in the turn of the event loop that was
triggered by the user action and so Firefox & IE's popup blockers deemed
the call to have happened outside the context of a user gesture and
prevented the window being opened.

Chrome, Safari & Edge have different heuristics and did not block the
popup before.

Fix the issue by opening the window directly when the user clicks on the
"Log in" button, at a dummy URL ("about:blank"), and then changing the
window's location once the authorization endpoint URL has been fetched.

Fixes #534
@codecov
Copy link

codecov bot commented Sep 8, 2017

Codecov Report

Merging #537 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #537      +/-   ##
==========================================
+ Coverage   90.93%   91.01%   +0.07%     
==========================================
  Files         136      136              
  Lines        5426     5529     +103     
  Branches      945      962      +17     
==========================================
+ Hits         4934     5032      +98     
- Misses        492      497       +5
Impacted Files Coverage Δ
src/sidebar/oauth-auth.js 98.08% <100%> (-0.38%) ⬇️
src/annotator/util/frame-util.js 86.88% <0%> (-0.3%) ⬇️
src/sidebar/util/random.js 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4192f10...df8b8a8. Read the comment docs.

robertknight added a commit that referenced this pull request Sep 11, 2017
Together with [1] this fixes the OAuth popup failing to appear when
clicking "Log in" in IE 11.

[1] #537
@seanh seanh self-assigned this Sep 11, 2017
@seanh
Copy link
Contributor

seanh commented Sep 11, 2017

Confirmed that I can reproduce the issue in master and that this fixes it. Also that this branch still works fine in Chrome too

Copy link
Contributor

@seanh seanh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I'll leave it up to you whether to do the one readability suggestion and merge, or to just merge

top: top,
width: width,
height: height,
}).replace(/&/g, ',');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability I think it'd be worth moving this into a strWindowFeatures(obj) function, or else just adding a code comment, I had to debug this and look into the window.open docs to figure out what was going on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment. This legacy API unfortunately has a somewhat suboptimal interface.

// user gesture in Firefox & IE 11 and their popup blocking heuristics will
// prevent the window being opened. See
// https://github.com/hypothesis/client/issues/534 and
// https://github.com/hypothesis/client/issues/535.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good to have this comment here

@robertknight robertknight merged commit b46cdb8 into master Sep 11, 2017
@robertknight robertknight deleted the firefox-oauth-popup-fix branch September 11, 2017 10:47
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.

"Log in" button triggers popup blocker in Firefox
2 participants