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

Implement workaround for print iframe removal on focus event #764

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

sensasi-delight
Copy link
Contributor

This pull request introduces an important update to the startPrint function in the src/utils/startPrint.ts file. The update implements a workaround to address the issue where the print iframe is removed immediately after the print dialog closes. This fixes the problem described in issue #187, where the iframe was being removed too early—before the print dialog appeared—causing the print preview to display the entire UI instead of the intended content.

  • src/utils/startPrint.ts: Added a focus event listener to remove the print iframe after the print dialog closes, addressing the lack of a reliable afterprint event in most browsers.

@MatthewHerbst
Copy link
Owner

Hey @sensasi-delight, thanks so much for this! I've been trying to think of situations where this might not work, or if it might cause problems for anything. Going to think about it for a few more days and then will merge if nothing comes up. Really appreciate you looking into this!

@sensasi-delight
Copy link
Contributor Author

Thank you for the response! Please let me know if there's anything I can clarify or improve further. I'm happy to help.

@jeremycharron
Copy link

jeremycharron commented Dec 16, 2024

Hello @MatthewHerbst , I was wondering if you were planning to merge this (as a beta version)?
I was considering doing a patch in my project, but I'd rather wait an official tag.

@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Dec 16, 2024

Hey! Apologies this has been delayed, I've been trying to find ways to break it. It seems like a simple change but event handlers have all sorts of weird behaviors so there's actually a lot of room for new edge cases to be introduced here. I will merge this and get it released as a beta in the next few hours

@MatthewHerbst MatthewHerbst merged commit 713be11 into MatthewHerbst:master Dec 16, 2024
@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Dec 16, 2024

I'm particularly concerned about the { once: true } so have been looking for ways to mess around with that

@MatthewHerbst
Copy link
Owner

3.0.3-beta-1 has been published, please let me know if you encounter any issues

@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Jan 6, 2025

@sensasi-delight this seems to have caused a new issue, #779, where browsers that don't automatically return focus to the page will never have onAfterPrint called. I looked into the HTML window.print spec and there is no requirement to return focus to the page from what I can find, though not doing so seems like very poor UX. Curious for your thoughts here.

@sensasi-delight
Copy link
Contributor Author

Dear @MatthewHerbst,

First of all, I want to apologize for the unintended issue caused by this pull request. It did resolve the problem on Chrome for Android on my end, but I didn't test it on Vivaldi, and it’s entirely possible that Vivaldi behaves differently. I completely agree that the lack of focus return is poor UX.

I’ve been thinking of a few alternative workarounds, such as leveraging the beforeunload event on the print window or using the visibilitychange event on the main window. I’ll experiment with these approaches and, if you’re open to it, I’d be happy to submit a new pull request once I find a reliable solution.

@MatthewHerbst
Copy link
Owner

Hey, all good, it happens! Appreciate you responding so quick! I'll take a look at the new PR in a bit, thank you!

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.

3 participants