Skip to content
New issue

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

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

Already on GitHub? # to your account

Not handling popup blockers on initial load #228

Closed
wants to merge 3 commits into from

Conversation

kajism
Copy link

@kajism kajism commented Jan 25, 2019

If pop-ups are blocked by your browser (Chrome), it can cause confusing exception Uncaught TypeError: Cannot read property 'document' of null followed by stack trace mentioning mranderson. The solution is to always allow pop-ups from your app under development URL (e.g. http://0.0.0.0:3449).

This probably occurs only when the browser was closed previously with separate re-frame-10x debugging window. I have spent a long time to figure out, so I think it should be mentioned in README.md to be easily searchable.

Thanks!

If pop-ups are blocked by your browser (Chrome), it can cause confusing exception `Uncaught TypeError: Cannot read property 'document' of null` followed by stack trace mentioning `mranderson`. The solution is to always allow pop-ups from your app under development URL (e.g. http://0.0.0.0:3449).

This probably occurs only when the browser was closed previously with separate re-frame-10x debugging window. I have spent a long time to figure out, so I think it should be mentioned here to be easily searchable.

Thanks!
@kajism
Copy link
Author

kajism commented Jan 25, 2019

screenshot from 2019-01-25 12-01-23

@kajism kajism changed the title Update Troubleshooting section of README.md Uncaught TypeError: Cannot read property 'document' of null Jan 25, 2019
@kajism
Copy link
Author

kajism commented Jan 25, 2019

Full stack trace:

Uncaught TypeError: Cannot read property 'document' of null
    at day8$re_frame_10x$events$open_debugger_window (events.js:355)
    at events.js:376
    at mranderson048$re_frame$v0v10v2$re_frame$std_interceptors$fx_handler__GT_interceptor_$_fx_handler_before (std_interceptors.js:126)
    at mranderson048$re_frame$v0v10v2$re_frame$interceptor$invoke_interceptor_fn (interceptor.js:186)
    at mranderson048$re_frame$v0v10v2$re_frame$interceptor$invoke_interceptors (interceptor.js:225)
    at mranderson048$re_frame$v0v10v2$re_frame$interceptor$execute (interceptor.js:335)
    at mranderson048$re_frame$v0v10v2$re_frame$events$handle (events.js:165)
    at Object.mranderson048$re_frame$v0v10v2$re_frame$router$IEventQueue$_process_1st_event_in_queue$arity$1 (router.js:633)
    at mranderson048$re_frame$v0v10v2$re_frame$router$_process_1st_event_in_queue (router.js:116)
    at Object.mranderson048$re_frame$v0v10v2$re_frame$router$IEventQueue$_run_queue$arity$1 (router.js:272)
    at mranderson048$re_frame$v0v10v2$re_frame$router$_run_queue (router.js:154)
    at router.js:527
    at Object.mranderson048$re_frame$v0v10v2$re_frame$router$IEventQueue$_fsm_trigger$arity$3 (router.js:601)
    at mranderson048$re_frame$v0v10v2$re_frame$router$_fsm_trigger (router.js:78)
    at router.js:318

@danielcompton
Copy link
Contributor

Hey, I'd rather fix the error and log a good warning rather than just adding a note in the documentation here.

Will be solved by writing info into js/console.
If pop-ups are blocked by Chrome, it can cause `Uncaught TypeError: Cannot read property 'document' of null`. This occurs only when the browser was closed previously with separate re-frame-10x debugging window. This fix writes an error message into console with info how to fix it.
@kajism
Copy link
Author

kajism commented Jan 30, 2019

Good idea, Daniel. So I committed a solution.

danielcompton added a commit that referenced this pull request Feb 3, 2019
Check if we were able to open the debugger window, instead of assuming
that it always works. If we couldn't open the window, show a dismissable
error message.

Thanks to @kajism for the prod on this and an initial solution.

Closes #228
@danielcompton
Copy link
Contributor

danielcompton commented Feb 3, 2019

@kajism I can see where the bug would be, but I'm having trouble reproducing it with Chrome on macOS. I've got Version 71.0.3578.98 (Official Build) (64-bit) on macOS 10.14.2.

Even when I disable popups on the dev site (on localhost and 0.0.0.0), they still pop up. Can you give me some more instructions on how to reproduce this?

In the meantime, I've pushed a fix for this. It shows an error message in the main window instead of logging to the console, as the user may not have their console open and miss the message.

@kajism kajism deleted the patch-1 branch February 4, 2019 08:32
@kajism
Copy link
Author

kajism commented Feb 4, 2019

@danielcompton I'm using the same version of Chrome as you e.g. "Version 71.0.3578.98 (Official Build) (64-bit)" on Linux Mint (4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux).

It can be reproduced this way:

  1. open an app using re-frame-10x in Chrome
  2. press re-frame-10x "Pop up" button. New window is created and displayed without problem.
  3. Close at first the app window than the debugger window
  4. repeat step 1 => pop up is blocked, error and stack trace displayed in the console. The funny thing is that when Ctrl-H is pressed now, re-frame-10x is normally displayed and can be even popped out without problem.

Daniel, unfortunately with the current solution committed to master (9462c33), re-frame-10x window is not displayed again and the error stack trace in console is suppressed, so it fails silently. If I don't notice the little "Pop up were blocked on this page" displayed in Chrome, I'm lost completely until I try to press Ctrh-H to see the new error info you have provided.

In addition the error message is displayed in re-frame-10x debugger even when the user don't care to open the separate pop up window.

@danielcompton
Copy link
Contributor

Great, thanks for the details, I can reproduce this now. The issue is only visible when re-frame-10x tries to automatically create a popup on initial page load. I'll fix it in this case too.

danielcompton added a commit that referenced this pull request Feb 19, 2019
If our JS tries to open a popup window without user interaction, Chrome
will block this, as it is indistinguishable from a popup ad. To
reproduce this issue:

1. Ensure the popup window is closed
2. In Local Storage, set "day8.re-frame-10x.external-window?" => "true"
3. Reload the browser
4. re-frame-10x will try and re-open the popup to restore the state

If the popup window is already open, Chrome doesn't prevent you from
're-attaching' to it.

Fixing this exposed a latent bug where we try to reopen an external
window before we have dimensions loaded from localstorage, so this
commit fixes that issue too.

Fixes #228
@danielcompton
Copy link
Contributor

I think I've cracked it this time, let me know if it's still an issue though. Thanks!

@kajism
Copy link
Author

kajism commented Feb 22, 2019

The latest release works nicely. Congratulations and thanks for all your work, Daniel!

@danielcompton danielcompton changed the title Uncaught TypeError: Cannot read property 'document' of null Not handling popup blockers on initial load Mar 6, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants