Bug 39307 - console.error on circ/circulation.pl page
Summary: console.error on circ/circulation.pl page
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Eric Phetteplace
QA Contact: Brendan Lawlor
URL:
Keywords:
Depends on: 37407
Blocks:
  Show dependency treegraph
 
Reported: 2025-03-11 16:52 UTC by Lucas Gass (lukeg)
Modified: 2025-04-11 07:56 UTC (History)
6 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.05.00
Circulation function:


Attachments
Bug 39307: Check to make sure there is a document.referrer (1.97 KB, patch)
2025-03-11 16:54 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 39307: Check to make sure there is a document.referrer (2.02 KB, patch)
2025-03-14 01:16 UTC, Phil Ringnalda
Details | Diff | Splinter Review
Bug 39307: Check to make sure there is a document.referrer (2.07 KB, patch)
2025-03-24 13:40 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 39307: Check to make sure there is a document.referrer (2.21 KB, patch)
2025-03-25 19:18 UTC, Eric Phetteplace
Details | Diff | Splinter Review
Bug 39307: Check to make sure there is a document.referrer (2.26 KB, patch)
2025-03-25 19:50 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 39307: Check to make sure there is a document.referrer (2.31 KB, patch)
2025-03-25 20:48 UTC, Brendan Lawlor
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2025-03-11 16:52:47 UTC
To recreate:

1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
Comment 1 Lucas Gass (lukeg) 2025-03-11 16:54:43 UTC
Created attachment 179173 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone
Comment 2 Phil Ringnalda 2025-03-14 01:16:04 UTC
Created attachment 179298 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone

Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Comment 3 Brendan Lawlor 2025-03-24 13:40:41 UTC
Created attachment 179638 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. APPLY PATCH
4. JS error should be gone

Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 4 Jonathan Druart 2025-03-24 13:44:24 UTC
Oops, sorry for the messy changes.

Thanks for the fast QA, Brendan!
Comment 5 Brendan Lawlor 2025-03-24 13:44:53 UTC
Makes sense to check if there is a referrer before running that code block. Passing QA. 

Thanks!
Comment 6 Eric Phetteplace 2025-03-25 17:13:33 UTC
Unfortunately this fails when 1) there is a referrer and 2) it is not additem.pl. While document.referrer is defined `document.referrer.split(window.location.origin + '/cgi-bin/koha/cataloguing/additem.pl?')[1]` is not be so you'll see an "undefined does not have method match" error.

QA plan should be:

1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
6. JS error should be gone in both instances
Comment 7 Eric Phetteplace 2025-03-25 17:21:08 UTC
This code works since it checks the split array index first before using match:

if (document.referrer.length) {
    const referrerSplit = document.referrer.split(window.location.origin + '/cgi-bin/koha/cataloguing/additem.pl?')
    if(referrerSplit[1] && referrerSplit[1].match(/frameworkcode=FA&circborrowernumber=/) ) {
        let urlParams = new URLSearchParams(window.location.search);
        let barcode = urlParams.get('barcode');
        $('#barcode').val(barcode);
        $('#mainform').submit();
    }
}

Happy to make a patch and apologies if it's uncouth to set back to failed QA without consulting anyone. I just noticed this console error on our instance and saw that it wasn't due to referrer being undefined but due to the problem I stated above.
Comment 8 Brendan Lawlor 2025-03-25 18:31:46 UTC
Hi Eric, thanks for catching this and changing to Failed QA. I apologize for not testing thoroughly enough.

Your explanation, test plan and code makes sense. If you submit a patch I can test and sign off.
Comment 9 Eric Phetteplace 2025-03-25 19:18:38 UTC
Created attachment 179701 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances
Comment 10 Lucas Gass (lukeg) 2025-03-25 19:50:58 UTC
Created attachment 179702 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances

squash

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 11 Brendan Lawlor 2025-03-25 20:48:05 UTC
Created attachment 179707 [details] [review]
Bug 39307: Check to make sure there is a document.referrer

To test:
1. Navigate to circ/circulation.pl?borrowernumber=X
2. See the console error `document.referrer.split(...)[1] is undefined`
3. Go to circ home circ/circulation-home.pl and search for a patron
4. See the console error when you select a patron or are taken directly to them
5. APPLY PATCH
5. JS error should be gone in both instances

squash

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 12 Katrin Fischer 2025-04-11 07:56:08 UTC
Pushed for 25.05!

Well done everyone, thank you!