window.onerror does not catch all errors - browser

For some reason I am able to catch all of the console errors except for "Unsafe JavaScript attempt to access frame with URL". Does anyone know why that error is filtered?
my code:
window.onerror = function(message) { alert(message); return true; };
Thanks ahead

Possible duplicate:
Display Javascript "same origin policy" violations
Catching same origin exception in Javascript?
I am not sure if that's the way to detect Same origin policy violations, since the window.onerror only catches runtime JS errors (see here).
For cross browser compatibility of error event you can check this out:
http://www.quirksmode.org/dom/events/error.html

Related

No such host is known in Test and Production

In my .Net Core controller I have a "PublishDraft" action. This works as expected in localhost during development. Once this is deployed to the Test or Production servers, this action returns the "No such host is known" error.
This is one of many actions on this controller, and they all work in Test and Production except for this one single PublishDraft() action. So this tells me it cannot be a DNS issue since all the other actions work.
[HttpPost("PublishDraft")]
public async Task<IActionResult> PublishDraft([FromBody] PublishDraftRequest request)
{
try
{
var existing = _unitOfWork.Drafts.GetAll(d => d.Id == request.DraftId, null, "DraftTags").FirstOrDefault();
if (existing == null)
{
return NotFound("Draft does not exist");
}
var created = await _unitOfWork.Drafts.PublishDraft(existing, User.Claims.GetUserId());
if (created.TreeNodeTypeId == (int)TreeNodeTypes.Private && created.ParentId != null)
{
await _unitOfWork.TreeNodeUser.UpdateUserPermissionsAsync(created.Id, created.ParentId, User.Claims.GetUserId());
}
return Created("TreeNode", created);
}
catch (Exception ex)
{
logger.LogError(ex, User);
return BadRequest(ex.Message);
}
}
Whether I test this using the web client (Angular) or PostMan in Test or Production, I get the same error on this single action.
The servers are IIS 10.
Any ideas why this is happening?
UPDATE:
To answer questions from the commenters about what the exception call stack shows, there is no exception! The controller action is never hit, so no exception is logged.
UPDATE 2 - Added screenshots of error
Dev Tools Header screenshot
(I removed the domain name in this screenshot)
Dev Tools Response screenshot
I found an interesting anomaly that changes the way I look at this issue, I'm only getting the "unknown host" error when the DraftId exists. But when I pass in a bogus DraftId, then I get the error message "Draft does not exist", which tells me that the controller action is actually being hit after all.
I still don't know why the "unknown host" error occurs in Test or Production and it works locally in development, but I'm adding some trace logging to see if I can find out where the issue is occurring.
Solved - Sept. 9, 2021
It's simply a cause of not being consistent on my part. It all came down to a trailing slash on an endpoint.
(Sprinkling trace logs throughout my code helped me track down the cause.)
My service needs to use the HttpClient to call an external api from inside the PublishDraft() method of the controller action.
My localhost appSettings has a config for the base endpoint like this:
"EndPointsConfig": {
"FileStore": "https://localhost:44314/"
}
The trailing slash is correct.
My Testing and Production appSettings properties were:
"EndPointsConfig": {
"FileStore": "https://filestore.domain.com"
}
The missing trailing slash caused the "No such host is known" error, since it had to concat the path to a method and with no slash / it was clearly incorrect.
Like this: https://filestore.domain.com/deleterange
Once the slash was added, it all worked!
Hopefully others find this useful in solving similar issues.

How to fix 'Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.'

I have the following error in the Chrome Dev Tools console on every page-load of my Node/Express/React application:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
This error makes a reference to localhost/:1. When I hover over this, it shows http://localhost:3000/, the address I'm viewing the app at in the browser.
Anyone have an idea what is going on? Most of the other threads I've found that bring up this error seem to be related to someone trying to develop a Chrome Extension, and even then they tend to have very few responses.
I'd been getting the exact same error (except my app has no back-end and React front-end), and I discovered that it wasn't coming from my app, it was actually coming from the "Video Speed Controller" Chrome extension. If you aren't using that extension, try disabling all of your extensions and then turning them back on one-by-one?
I found the same problem when developing the Chrome extensions. I finally found the key problem.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
The key problem is that when background.js sends a message to the active tab via chrome.tabs.sendMessage, the content.js on the page is not ready or not reloaded. When debugging. We must ensure that content.js is active. And it cannot be a page without refreshing , The old pages don not update you js itself
Here is my code:
//background.js
chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response);
});
});
//content.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
console.log(request, sender, sendResponse);
sendResponse('我收到你的消息了:'+JSON.stringify("request"));
});
The error is often caused by a chrome extension.
Try disabling all your extensions, the problem should disapear.
Solution
For Chrome:
You have the window open with the console error, open up a second new window.
In the second window, go to:
chrome://extensions
Disable each extension by toggling (the blue slider on the bottom right of each card), and refresh the window with the console after toggling each extension.
Once you don't have the error, remove the extension.
If you are an extension developer see this Chrome Extension message passing: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
The core of the problem is that chrome API behavior change and you need add a workaround for it.
You need to handle window.chrome.runtime.lastError in the runtime.sendMessage callback. This error just needs to be handled. Below is my code:
window.chrome.runtime.sendMessage(
EXTENSION_ID,
{ message:"---" }, // jsonable message
(result) => {
if (!window.chrome.runtime.lastError) {
// message processing code goes here
} else {
// error handling code goes here
}
}
);
});
🙂simple answer:🙂
if you have no response from another End it will also tell you Receiving end does not exist.
detailed answer:
if you have no answer from another end it will also tell you Receiving end does not exist. so if you have any callBack function which should use response in your .sendMessage part, you should either delete it or handle it if you probably have no response from another side.
so
if i wanted to re-write Simple one-time requests section of Message passing documents of google API i will write it with error handlers for callback functions in message-sending methods like this:
Sending a request from a content script looks like this:
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
Sending a request from the extension to a content script looks very similar, except that you need to specify which tab to send it to. This example demonstrates sending a message to the content script in the selected tab.
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
});
On the receiving end, you need to set up an runtime.onMessage event listener to handle the message. This looks the same from a content script or extension page.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting === "hello")
sendResponse({farewell: "goodbye"});
}
);
Removing 'Udacity Frontend Feedback' chrome extension solved the issue for me.
This was happening in Chrome for me and I discovered it was McAfee WebAdvisor. Once I disabled it, the message went away:
The simple fix is to return true; from within the function that handles chrome.tabs.sendMessage.
It's stated
here.
(this is similar to other answers)
I removed "Video Speed Controller" Chrome Extension and the error was removed.
It worked for me like this. In your case there may be some other extensions too which may cause this error.
It was tab bnundler for me: https://chrome.google.com/webstore/detail/tab-bundler/ooajenhhhbdbcolenhmmkgmkcocfdahd
Disabling the extension fixed the issue.
It was a few extensions for me. Disabling and then re-enabling fixed the problem though. Grammarly was one of them. Hope the errors don't return.
Oddly enough, for myself I simply disabled all my extensions and the error went away.
However, after re-enabling all of the ones I disabled, the error was still gone.
I was testing my extension on edge://extensions/ page/tab. Testing it on another tab solved this issue. I think this may also occur for chrome://extensions/.
This is caused simply by installed chrome extensions, so fix this first disable all chrome extensions then start to enable one after another to detect which extension is cause you can enable the remaining.
in my case removing 'adblocker youtube' extension work for me
For me the error was due to the onelogin chrome extension. Removing it fixed the issue.
Cacher Extension in my case - but yeah disable each and then reload page
This is usually caused by an extension.
If you don't want to disable or remove the extension which causes this error, you can filter out this specific error by typing -/^Unchecked\sruntime\.lastError\:\sCould\snot\sestablish\sconnection\.\sReceiving\send\sdoes\snot\sexist\.$/ in the Filter box in the console:
As far as I've seen, this filter will stay until you remove it manually, you can close and reopen the console, restart Chrome, etc as much as you want and the filter will never be removed automatically.
I get the message only on the first Chrome page =
When Chrome is not running, and I open it - either directly or by double-clicking on a page on my desktop.
(I don't know if this matters, but I have "Continue running background apps when Google Chrome is closed" off.)
So, I'm assuming it's Chrome's crap spying/"enhancing user experience" attempt.
I don't know what it's trying to send, but I'm glad it's not able to! :)
So, second (or any but first) tab has no error.
== No need to disable anything (extensions, etc.).
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
I "achieved" this error after
installing the Debugger for Chrome extension in Visual Studio Code,
debugging my code, and
closing and reopening the non-debugging Chrome window. (I had left Chrome running my app while debugging.)
Solutions:
Stop using the extension.
Refresh the non-debugging Chrome window.
Use a different debugger.
Of course, the console error reappears when I redo steps 2 and 3 above with the Debugger for Chrome. This encourages me to use other debuggers instead. Then I don't mistakenly think my own code produced the console errors!
For me this was caused by :
Iobit Surfing Protection & Ads Removal extension
which comes with Iobit advanced system care software. However, the console might provide you with relevant information on what you need do disable or the cause for that problem.
The likely cause of this error, as per google searches is because that extension which causes the error, might be using the chrome.runtime.sendMessage() and then tries to use the response callback.
Error shown in the console
Hope this information helps. Have a great day!
For chrome extension development, it's an error thrown by chrome.tabs.sendMessage method.
Here is the link of related documentation: https://developer.chrome.com/docs/extensions/reference/tabs/#method-sendMessage. In the link you can find the description for the callback function: If an error occurs while connecting to the specified tab, the callback is called with no arguments and runtime.lastError is set to the error message.
According to documentation above, the error is because of the specified tab. I restart chrome and reloaded the extension, and this issue is fixed
I solved this in following way. This is mainly chrome extension problem, try to first empty cache and hard reload for this inspect any window and hold reload button about 2 second then it will appear 3 options click last one which is mentioned above then go to manage extensions and turn off one by one and then turn on again one by one and check it's gone or not.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
chrome.runtime.lastError
It's an error that appear in the Chrome devTools console.
And it's related to Chrome Chrome Message Passing
Because of the 'rigid structure' of the Chrome platform, it's not easy to pass data between different Chrome windows/tabs, as it's common to do in the 'object oriented' programming languages.
In Chrome extensions, usually, there is not a single file of code, that runs for all pages or tabs.
It's a common use, to build many different files of code in javascript, for different Windows/tabs/url address.
So, when the software, need to pass data from different windows/tabs/url, it's made using 'message passing'
The 'message passing', allow to send a 'message' and wait to receive a message as 'callBack'
But sometimes happens, in example, that the url of a window, or a tab, change, when there is a 'message passing' function which has been triggered, but still not returned.
If this situation it's not managed by code (as wrote TechDogLover OR kiaNasirzadeh), or it's an old extension not updated, this error can arise.
So as others users said, it could be an extension, which is running in your Chrome.
But if your window doesn't crash, it doesn't have much sense disable an extension because of such message appear in the devTools Console.
And it doesn't have sense try to understand how to fix it (if you are not the developer of the software which is causing the error), because the variables are so many, that it's not said that the error will be triggered again, in the same situation.
In those cases, in my opinion, if you really want to do something, a good thing to do could be, once you find the extension that cause the error, contact the extension developer and report it.
And if you are the developer, you could check for a missing
if(!chrome.runtime.lastError){
// here if there is no error
} else {
// here if there is an error
}
Or, also you could check your code, if you did more than one callBack, e.g. as explained there
wOxxOm comment
I also encountered this problem when I was developing chrome extensions.
Error: Could not establish connection. Receiving end does not exist.
The error message from chrome.tabs.sendMessage
The solution is to make it return the promise and use catch to handle the error and define it yourself. Example
Apparently an error occurred during browser startup and the browser did not launch extensions such as stylish, adblock. I closed the browser and reopened it and my page worked without errors.

How do I manually refresh-token while creating apps using Zapier CLI

I want to perform refresh token but my gateway gives HTTP response 403 instead of 401 so I cannot use 'autoRefresh' feature of Zapier.
I tried throwing 'RefreshTokenException' when the response status is 403 as given below:
return responsePromise
.then((response) => {
if (response.status == 403) {
throw new RefreshTokenException();
}
...
});
But upon doing this I get an Error from Zapier (while creating zaps) stating:
RefreshTokenException is not defined
Can anyone help me with manually refreshing token using Zapier CLI platform for app creation?
David here, from the Zapier Platform team. Sorry for the slow reply, we're just now seeing some of these.
It's not defined because that's not an error we define. You've got the right idea, you just need to use RefreshAuthError instead. See these docs.
​Let me know if you've got any other questions!

Getting error "SecurityError (DOM Exception 18): The operation is insecure" when storing data in localStorage of UIWebView

I am developing one sample Xamarin.Forms Application and in this application I'm using WebView for tyro payment gateway integration and also create WebViewRenderer for store data in localStorage of UIWebView. and I'm getting security error (SecurityError (DOM Exception 18): The operation is insecure).
Tyro payment gateway web url is "https://iclient.test.tyro.com".
Please have a look below my code and help me
string subkey = "window.localStorage.setItem('webTta.integrationKey','integrationKey')";
string key ="try { "+subkey +"; } catch (e) { alert(e); }";
IntegrationKey = _uiWebView.EvaluateJavascript(key);
My issue is solved. This error was occurring by storing data before loading page. I solved this issue by call EvaluateJavascript method after loading a page.
If you try to call an EvaluateJavascript method in blank WebView then it is also occurring.

CouchDB returning HTTP 403 on required field validation

I've been working for the last couple of weeks on a small Couch/NodeJS project where I need some field validation (required, type...). I solved this by adding validate_doc_update to the design doc.
After doing some test I realized that I was receiving 403 forbidden HTTP code instead of 400 bad request, which I think is more appropriate in this use case.
CouchDB Documentation says that I can just throw one of these error objects:
Throws: forbidden error to gracefully prevent document storing. (403)
Throws: unauthorized error to prevent storage and allow the user to re-auth. (401)
Any ideas on what's the best approach to manage this kind of validation issues?
Update:
content of validate_doc_update:
function (newDoc, oldDoc, userCtx){
function require(field, message){
message = message || "Block must have a " + field;
if (!newDoc[field]) throw({forbidden : message});
};
if(newDoc.type == "block"){
require("name")
}
}
I know that throw({forbidden: message}) will give 403... Is there any way to change that behaviour on CouchDB or should Ibuild my own validation middleware on express?
Yeah, this is an ugly corner of CouchDB actually. I'm surprised there's still not a provision to respond with a 422 (which is much more appropriate for an invalid document than a 403), but yes - what we did was add our own middleware to do the right thing.

Resources