Unusual javascript HTTP caching / undefined issues - javascript

Ok. I have never seen anything like this before and I am quite confused... On a website I am working on, there are two JavaScript includes. (Well, many more, but the problem occurs with only two). We'll call these A.js and B.js.
A.js defines a JavaScript singleton A. Likewise B.js defines a JavaScript singleton B. The B class depends on methods from A.
I have almost all my code wrapped up in try { ... } catch { ... } blocks, and on error, the system generates an AJAX request to email me the details of the error.
On one system here in my office (Firefox 3.0 for Mac) I am seeing the strangest behavior. Once in a while, maybe once every hour or two, but with no specific pattern, I get an error email from class B: "ReferenceError: A is undefined."
I have no idea why/how A would be undefined sometimes. When I look in the apache logs, during the times I receive the error, the client is requesting /A.js, before requesting /B.js, and the server is responding with a 304 (Not Modified)
I somehow suspect the issue is that the file has expired from the client cache however the server doesnt send the file thus it is never executed and A is undefined. But that's just a guess and I don't understand why that would happen. And if I am guessing right, how do I fix it???
If it matters, mod_disk_cache was enabled on the server, and I have disabled it to see if that was causing the problem. If so, maybe this belongs on ServerFault...
Any suggestions very welcome!!

If you have the Webdevelopers toolbar installed in Firefox, activate "Disable Cache" it helps a lot on debugging.

start calling the first js function after! the page has loaded, do this by <body onload="startmyfunction()"> or similar.

Related

"A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received", What does that mean?

I'm working on a React application and I use some npm modules, one of which I had to build myself. (my NPM package:
https://www.npmjs.com/package/modale-react-rm).
It is a simple modal that opens and closes with a useState().
After importing my package, I have an error in my console that appears suddenly after a few seconds without performing any actions.
Uncaught (in promise) localhost/:1
>{message: 'A listener indicated an asynchronous response by r…age channel closed before a response was received'}
message: "A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received"
>[[Prototype]]: Object
>constructor: ƒ ()
>[[Prototype]]: Object
/* sometimes there are specific elements in addition but I could not check when they appear and when not */
Promise.then (asynchrone)
(anonyme) #content_script_bundle.js:108
handleNewFeatures #content_script_bundle.js:101
handleUpdatedNodes #content_script_bundle.js:101
(anonyme) #content_script_bundle.js:101
childlist(asynchrone)
0 #purplebox.js:1
(anonyme) #purplebox.js:1
v #purplebox.js:1
It doesn't block my pages, nor does it prevent the proper functioning of its features, but it's an error and I think it should be fixed and maybe help other people who have the same problem.
I specify that I do not make any async request in this project. Everything is local and the few data I use are directly imported in raw.
I don't know where Purplebox.js comes from as well.
This issue is a cross-origin request issue and it is caused by various Chrome Extensions.
I had this too in my Angular app and after testing it in the incognito mode, the error didn't show up anymore.
More info: Google Forum
/Edit:
If you are an extension developer coming here: You need to return true when fetching data from cross-origins. More info: Chromium Project
In my case, it is caused by Ghostery extension, if this error appears in your local host, you need to add it to the trusted sites list of Ghostery and the error will be gone.
It has been discussed in the webextension-polyfill library, which is used by many extensions (including Ghostery). There was a recent change in Chrome that introduced to the error message.
For projects that are using the polyfill, I would expect the warning to go away if a fix is merged. Note that the polyfill library is used, since only Firefox implements the new promised-based runtime.onMessage, while Chrome still enforces the original callback-style API.
Note that there is an open pull request in the webextension-polyfill library already. It has not been merged, but according to my tests, it solves the problem. So, if you need a quick fix for a project that uses the library internally, you can manually apply the patch with patch-package. For instance, this is how such a change would look like in Ghostery.
The background script (service worker in MV3) could be going to inactive state without sending a response back to a message it received from a content script.
Example:
Background script:
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// ... handle message
return true // Error message says you already return true
})
Most MV3 APIs are asynchronous and can return promises when it makes sense to do so. (In some cases, like event listeners (e.g.: chrome.tabs.onRemoved), returning a promise wouldn't make sense). Reading a response back however can be done using callbacks or promise-style.
Content script: method 1 to read response:
chrome.runtime.sendMessage('ping', (response) => { /* read response */ })
Content script: method 2 to read response:
chrome.runtime.sendMessage('ping').then(response => { /* read response */ })
The issue you are facing is this: background script does not invoke sendResponse() for one/more messages it received and went inactive (causing the message channel to close). However, the content script that sent the message is waiting for the response.
Please check your message senders & handlers.
I had the same error. I removed the Tampermonkey extension and tweaked my AdBlock extension and then it worked for me.
I encountered the same issue couple of days ago, and found out that the source of error is located in the background.js.
it's caused by the runtime Message Handler. to solve it, just add a third parameter as a callback function to chrome.runtime.onMessage.addListener.
forgot how i found the solution, but it works for me.
// to avoid the error, the parameter [sendResponse] is necessary!
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
// do something ...
// this line seems meaningless but you have to invoke it to avoid error.
sendResponse({damn: true});
});
This error is related to ad blockers or similar. Just exclude the site for this application.
In my case it was AdBlock app. It kept showing this error in the console when working with LiveServer or FiveServer. It does not affect anything, but it is very annoying
I had the same error on my react app when i introduced an infinite loop through useEffect, the thing is that you most likely won't see too much change in your app or problem. For me it even helped reload some state for functions that i was still to write but over time it will introduce bugs and performance issues.
Avast Online Security & Privacy 22.11.173 is causing the same issue.
I had the same issue on my Windows 11 machine.
I added these lines at the bottom of the hosts file in the drivers/etc directory:
127.0.0.1 localhost
::1 localhost
This solved the problem for me.
I faced the same error. Where class Component didn't show any response over display.
Solution : Syntax error in spelling "render" => ~"rendor"~

xhttp.send works once but fails the 2nd time

I have the following javascript that works happily the 1st time but fails the second time..
xhttp = new XMLHttpRequest();
xhttp.open("POST","FINDMOVES",false);
xhttp.send(text);
This send is actually being received by the server and a respone is written by the server. The server is my own and written in assembler.
The java console reports:-
POST http://localhost:1024/FINDMOVES net::ERR_EMPTY_RESPONSE
Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:1024/FINDMOVES'.
This code works happily where it is used in other programs.
I am aware that:- "[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience" but it is not java's decision as to what my end user experience is like. It is mine.
Anyone got any clues ??
further to this...(and some background)
I have a runtime module that acts as a web server. This is used to serve on-line programs and therefore be portable between windows/linux. It is statically linked to application programs.
I have a dozen application programs happily using this server.
I have 1 near identical application that is okay but it's "twin" progran is failing. I have been stepping through the programs for a couple of days now and I have noticed the following:-
The SYS_ACCEPT call returns the same file descriptor for all programs that work while in the failing program, after a few calls, it returns a different file descriptor and as soon as that is the case the web browser does not see the response (even though it was written without error)
Anyone know what's going on here ?
The answer to this is not what I would have expected and I came across it completely by accident when I commented out some file access in the application program to make the strace ouput clearer.
The application was at fault in that it opened a file in an initialisation section but mistakenly closed it each time it sent a response back to the server. It effect it opened once but closed many times. In some way this confused the linux kernel (?) and it was made evident in the SYS_ACCEPT call.
I have to admit, I do not understand why this occurs so if someone can shed some light on why this happens I would appreciate it. For now though it looks like everything is back to working again.
Oh, I was getting a -512 back from the SYS_ACCEPT call but could never find out what that represented. Perhaps it means "Hey dude, stop closing that bloody file" !!

Finding a strange Javascript function 'window.ueLogError' in a PhantomJS error message

I'm working on a project that involves retrieving multiple websites with PhantomJS and when I try to load Amazon.com, PhantomJS crashes while trying to evaluate this function with the error:
TypeError: 'undefined' is not a function (evaluating 'window.ueLogError')
The weird thing is that I can't seem to find any documentation or explanation of any kind for window.ueLogError. A google search gives a handful of websites with scripts that contain it, but it doesn't seem to be a part of any documentation I can find. Does anyone know anything about ueLogError?
The window object is the global sink in the browser. Every variable that you define globally (e.g. jQuery's $) is a property in window. ueLogError is not some kind of standardized JavaScript function. It is most likely some function for an advertisement script.
Not all resources that a page requests as part of the page load are actually successfully loaded. Some requests fail due to SSL problems. Some requests fail, because the user agent string is not supported. Some requests fail because of unknown reasons.
You can register to the onConsoleMessage, onError, onResourceError, onResourceTimeout events (Example) to see whether there are errors. Usually you will find that some JavaScript file wasn't loaded which would have contained ueLogError which another script depends on.

page area not refreshing using jquery and setinterval

i am trying to refresh a particular area of my php page, which will load the updated information from database. My code are working on localhost. But, when the same code i'm trying to execute on my domain. Then, it is not refreshing and not showing updated information, and i don't why... Anybody have any idea..
setInterval(updateShouts, 10000 );
function updateShouts(){
$('#refresh').load('ajax/check.php');
};
this is the code, which i'm using for refreshing the
.
I'd check that the URL is correct:
You can use Firebug (or another Javascript debugger) to watch the request going out, and you can see if it was a 404 error or if it worked.
Also, in the Console, just type in $('#refresh') and make sure it returns an actual object.
if it just displays [] or undefined, then the selector is wrong.
Try:
function updateShouts()
{
$('#refresh').load('ajax/check.php');
};
setInterval(function(){updateShouts();}, 10000 );
Problem is with most localhost dev servers the configuration, security, etc.. is usually at the load end of the scale vs a host else where. So that may or may not be part of the issue, I couldn't say for sure though
Edit I agree with the notion of checking to make sure the path ajax/check.php is valid also. And that Firebug is a very handy tool to have when developing with jquery (or javascript stand alone)

Crm 2011 with no javascript customizations gives onload errors

we are getting the following error in almost all create or edit entity forms. the systems is not customized at all and it works perfectly:
There was an error in the fields customized event.
field:window
event:onload
error:object doesn't support this property or method
after debugging the error I found out that it is happening in FormScript.js.aspx page in the following code block:
var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,null);
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,eContext)
Mscrm.Form_onload();
Mscrm.Form_onload() is what causing the error to happen.
do you have any idea why is this happening?
It was a server side problem. I don't know exactly why it happens. we also tried to do an installation repair but that didn't solve it. Finally, we installed a fresh CRM 2011 copy on a new server, imported the database and ran Data migration manager. and the error disappeared.
Are you absolutely positive there is no script attached to run on load of any of the entities that are having issues? That particular function should just run any custom script you have on the entity, so I don't see any other cause.
Odd, there is certainly some garbage in there somewhere
function crmForm_window_onload_handler(eventObj,eventArgs){
try{
var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,null);
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,eContext)
loadInsideView();
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,1,null,eContext)
CEI.Initialize();
} catch(e) {
displayError('window', 'onload', e.description);
}
}
Here is one from our system on the account form. I have no idea how this could have happened, but I would check the events for the page (not just the onload). I would also try adding a JavaScript web resource with a generic event to the onload to see if by toggling it on, the system might clean itself up. You may have to call Microsoft or find the issue in your 4.0 and fix it to do another re-install. I feel for you on this one!

Categories

Resources