Skip to content

fix: use referrer for toolbar return link when available#1501

Open
ParthAggarwal16 wants to merge 1 commit intointernetarchive:masterfrom
ParthAggarwal16:fix-1494-referrer
Open

fix: use referrer for toolbar return link when available#1501
ParthAggarwal16 wants to merge 1 commit intointernetarchive:masterfrom
ParthAggarwal16:fix-1494-referrer

Conversation

@ParthAggarwal16
Copy link

fixes the toolbar return link to use the referrer when available instead of a static URL

This change updates the toolbar to use document.referrer when it’s available, ensuring that the return link directs the user back to the actual previous page

closes #1494

@MarcCoquand
Copy link

Hi! Is this still being worked on @ParthAggarwal16 ?

@ParthAggarwal16
Copy link
Author

Hello @MarcCoquand , this is ready to review from my side. please let me know if any changes are needed

@MarcCoquand
Copy link

It looks good to me

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates BookReader’s toolbar “return” link so it can point back to the user’s actual previous page (via document.referrer) instead of always using a static bookUrl, addressing the navigation break described in #1494.

Changes:

  • Add logic to prefer document.referrer when present and same-origin.
  • Fall back to br.bookUrl if referrer is absent, cross-origin, or unparsable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 51 to +63
if (br.bookUrl && br.options.enableBookTitleLink) {
// Use referrer if available and from same origin, otherwise use bookUrl
// This allows returning to the previous BookServer Explorer App page
let returnUrl = br.bookUrl;
const referrer = document.referrer;

if (referrer) {
try {
const referrerUrl = new URL(referrer);
const currentUrl = new URL(window.location.href);
if (referrerUrl.origin === currentUrl.origin) {
returnUrl = referrer;
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The new return-link behavior (preferring document.referrer when same-origin) isn’t covered by tests. Since this repo already has Jest tests for Toolbar.js, add unit tests for buildToolbarElement() covering: (1) defaulting to br.bookUrl, (2) same-origin referrer override, (3) cross-origin referrer ignored, and (4) invalid referrer string fallback.

Copilot uses AI. Check for mistakes.
if (referrerUrl.origin === currentUrl.origin) {
returnUrl = referrer;
}
} catch (e) {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

catch (e) introduces an unused variable, which violates this repo’s no-unused-vars ESLint rule and will fail npm run lint. Use an empty catch binding (catch { ... }) or otherwise reference the error variable.

Suggested change
} catch (e) {
} catch {

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +57
const referrer = document.referrer;

if (referrer) {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace on the blank line after const referrer = document.referrer;, which violates the repo’s no-trailing-spaces ESLint rule and will fail npm run lint. Remove the whitespace (or the blank line).

Copilot uses AI. Check for mistakes.
Comment on lines +67 to 69
}

$titleSectionEl.append(
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace on the blank line just before appending the <a> element, which violates the repo’s no-trailing-spaces ESLint rule and will fail npm run lint. Remove the whitespace (or the blank line).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to return to previous BookServer Explorer App page from BookReader

4 participants