-
-
Notifications
You must be signed in to change notification settings - Fork 41
Fix resume download popup #99
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ export default function ClientResumeButton({ username }: { username: string }) { | |
| const [isLoading, setIsLoading] = useState(false); | ||
|
|
||
| const handleDownload = async () => { | ||
| const newWindow = window.open("", "_blank"); | ||
| try { | ||
| setIsLoading(true); | ||
| const response = await fetch(`/api/resume?username=${username}`); | ||
|
|
@@ -22,9 +23,14 @@ export default function ClientResumeButton({ username }: { username: string }) { | |
|
|
||
| const blob = await response.blob(); | ||
| const url = URL.createObjectURL(blob); | ||
| window.open(url, "_blank"); | ||
| if (newWindow) { | ||
| newWindow.location.href = url; | ||
| } else { | ||
| window.open(url, "_blank"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the suggestion for the initial window.open(url, "_blank", "noopener,noreferrer"); |
||
| } | ||
| } catch (error) { | ||
| console.error("Error downloading resume:", error); | ||
| if (newWindow) newWindow.close(); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of opening a blank window first to work around popup blockers!
For enhanced security and to follow best practices, when using
window.open("", "_blank"), it's recommended to include"noopener,noreferrer"as the third argument (window features).noopener: Prevents the new window from having access towindow.opener, which mitigates potential tabnabbing attacks.noreferrer: Prevents the browser from sending theRefererHTTP header to the new page.While the immediate navigation is to a
blob:URL, adopting this practice consistently is beneficial. What are your thoughts on applying this here?