We inconsistently see this error in our logs:
Cannot read property 'substring' of undefined
It occurs on this line of code: var sPageURL = window.location.search.substring(1)
Unfortunately, the error is not consistently reproduced, but the flow is:
Open new window via JavaScript.
In new window, invoke this line of code.
Based on Googling, internal testing, and answers like this, it seems like window.location.search should at worse be an empty string, but never undefined. If window or location were undefined, then it would be expected for the error to appear differently.
Under what conditions could window.location.search be undefined?
All browsers should (and all the usul suspects do) implement the w3c guidelines for this property. These state:
The search attribute's getter must run these steps:
- If this Location object's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
- If this Location object's url's query is either null or the empty string, return the empty string.
- Return "?", followed by this Location object's url's query.
So this property should either throw a SecurityError or be an empty string. If your not seeing this then it's a browser with a bug or a browser that does not implement this specification correctly (possibly a web crawler).
Either way providing your abiding by the w3c guideless. I'd say this isn't your problem. Your job is to write code that abides by the specifications of the w3c, it's the browsers job to stick to these. If they don't, all bets are off. Any number of things could break.
You do state:
it happens on chrome
But I'd question the validity of this. It's very hard to actually identify a browser and it's trivial to spoof a browsers user-agent.
Kudos to Maxim's comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With