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

Realtime graph javascript error in Chrome #3580

Closed
ahouston opened this issue May 28, 2020 · 5 comments
Closed

Realtime graph javascript error in Chrome #3580

ahouston opened this issue May 28, 2020 · 5 comments
Labels
bug Undesired behaviour unverified Some days we don't have a clue

Comments

@ahouston
Copy link
Contributor

ahouston commented May 28, 2020

jQuery + Chrome race condition

When starting a realtime graph in Chrome, the following javascript error occurs, and the graph isn't rendered:

Uncaught ReferenceError: imageOptionsChanged is not defined
    at HTMLDocument.<anonymous> (graph_realtime.php?top=0&left=0&local_graph_id=14317:227)
    at mightThrow (jquery.js?11c05eb286ed576526bf4543760785b9:3557)
    at process (jquery.js?11c05eb286ed576526bf4543760785b9:3625)

I had a look at the code and it appears that the jQuery document ready $(function() {}) in graph_realtime.php is executing before the realtime.js file is loaded, so the imageOptionsChanged() function isn't defined at this point.

I tried this in Firefox and it seemed to work OK there, so likely something specific to browsers based on the Chromium V8 engine.

The simple fix is to change the graph_realtime.php ready function to use the $(window).on('load',function{}) binding like so:

$(window).on('load', function() {
	imageOptionsChanged('init');
	myCountdown = setTimeout(function() {
	     countdown_update();
	}, 1000);
});

I've tested in Chrome and Firefox and it seems to work fine with the change.

To Reproduce

Steps to reproduce the behavior:

  1. Chrome Version 81.0.4044.138 (Official Build) (64-bit)
  2. From the graph view, click on the realtime icon

Desktop (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome Version 81.0.4044.138 (Official Build) (64-bit)
@ahouston ahouston added bug Undesired behaviour unverified Some days we don't have a clue labels May 28, 2020
@netniV
Copy link
Member

netniV commented May 28, 2020

There is actually an issue open for this but the race condition makes sense. We really need to ensure the realtime.js is loaded before we initialise then.

@ahouston
Copy link
Contributor Author

Sorry, I don't know how I missed the open issue, I did a cursory search before I raised this but couldn't see anything open for realtime...

The "fix" I put in seems to be working OK, but it may need to be tested against multiple browsers before passing muster.

@netniV
Copy link
Member

netniV commented May 28, 2020

To be fair, the previous one was closed prematurely, and I'd not reopened it yet despite seeing the evidence presented as I hadn't had a chance to diagnose it myself.

@hiddenicon
Copy link

Yes I had #3538. Just tested this code change for the onload and I'm working again as well. Tested on a few browsers and PCs we initially had issues with, all good now.

@netniV netniV closed this as completed May 29, 2020
@netniV
Copy link
Member

netniV commented May 29, 2020

Thanks for the help and support on this one.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour unverified Some days we don't have a clue
Projects
None yet
Development

No branches or pull requests

3 participants