are there any JS errors that may reveal DOM content - javascript

We want to start logging all client side errors to a server. The catch is that there potentially be a lot of customer sensitive data in the DOM that we can't know about or we would break our contracts with them.
The errors we want to log are browser or angular generated (from the exception handler), not from console.error.
I can't think of any errors that might do this, but thought I'd open source the question. Are there any JS or angular errors you can think of that would reveal content inside the DOM? The elements themselves are okay.

Related

Console Warning: "Notion Warning Reverting mutation of..." does this mean all mutations are now prevented?

Here is the screenshot of the warning I am receiving while either;
changing the contentEditable attribute of a node to "true" from "false"
executing range.surroundContent(). Details of error will differ on this one, but the general note is the same.
via the chrome extension I am building.
I couldn't find much info on the error posted, so I would like to know whether my understanding that any DOM manipulations that execute or require a mutation is now prevented by the site? Or is there a workaround for this as well please?
https://github.com/obahareth/notion-rtl/issues/28#issuecomment-998233268
Seems like Notion has been deploying a protection mechanism to prevent DOM manipulations via external scripts being embedded. Just leaving note.

Track JS CSS Asset Errors on page load

Is it possible to track the number of errors and warning thrown by a browser on page load using javascript?
For example CSS Assets missing or images missing or js script errors? I don't need a detailed log but maybe a count of each type of error.
Like a count of CSS, Assets missing and JS Errors?
This needs to be tracked using JS and not in the console. The script needs to collect all these errors from the console and send them back to my server.
Yea, absolutely. There are a number of ways to do this.
For JavaScript, you can capture errors by listening to window.onerror. This will give you the error information and you can AJAX the data back to your infrastructure.
If you don't want to support the infrastructure log them yourself, you can use a JavaScript Error Logging service like TrackJS to do this automatically.
For Asset load failures, you can attach onerror listeners to the css tags, although this won't work in all browsers. You could send the load failures back to the same logging infrastructure.
You should also check out the new proposed standard on Network Error Logging, which might be relevant for what you're trying to do.

Programatically retrieve count of javascript errors on page

I'd like to write a test case (using Selenium, but not the point of this question) to validate that my web application has no script errors\warnings or unhanded exceptions at certain points in time (like after initializing a major library).
This information can easily be seen in the debug consoles of most browsers. Is it possible to execute a javascript statement to get this information programatically?
It's okay if it's different for each browser, I can deal with that.
not so far read about your issue (as far as I understood your problem) here
The idea be the following:
I found, however, that I was often getting JavaScript errors when the page first loaded (because I was working on the JS and was introducing errors), so I was looking for a quick way to add an assert to my test to check whether any JS errors occurred. After some Googling I came to the conclusion that there is nothing built into Selenium to support this, but there are a number of hacks that can be used to accomplish it. I'm going to describe one of them here. Let me state again, for the record, that this is pretty hacky. I'd love to hear from others who may have better solutions.
I simply add a script to my page that will catch any JS errors by intercepting the window.onerror event:
<script type="text/javascript">
window.onerror=function(msg){
$("body").attr("JSError",msg);
}
</script>
This will cause an attribute called JSError with a value corresponding to the JavaScript error message to be added to the body tag of my document if a JavaScript error occurs. Note that I'm using jQuery to do this, so this specific example won't work if jQuery fails to load. Then, in my Selenium test, I just use the command assertElementNotPresent with a target of //body[#JSError]. Now, if any JavaScript errors occur on the page my test will fail and I'll know I have to address them first. If, for some strange reason, I want to check for a particular JavaScript error, I could use the assertElementPresent command with a target of //body[#JSError='the error message'].
Hope this fresh idea helps you :)
try {
//code
} catch(exception) {
//send ajax request: exception.message, exception.stack, etc.
}
More info - MDN Documentation

Where does rails log errors in javascript?

I'm fairly new to Ruby on Rails so sorry if the answer is obvious, I couldn't find anything via search. Right now I have my view rendering _box.js.erb which simply draws a box. Inside _box.js.erb, which works correctly under normal circumstances, I introduce a simple syntax error like an unmatched parenthesis. When I load the webpage, my box doesn't show up. I look in logs/development.logs and it has no mention of my javascript syntax error. Is this error being caught somewhere? If so, how can I display it?
The error occurs on the client, not the server, so ROR cannot log it.
If you're using Firefox, install Firebug. Other browsers have JavaScript consoles, usually opened by pressing F-12 or looking on the "developer" options on the application menus.
You could also create a controller to accept javascript errors, so when there's a client side error you can just send it to a javascript error collection endpoint which in turn could take the contents of the error and add it to the Rails log or whatever log.
This old gem does that. I realize this questions is 8 years old.

Getting data from the browser's console using javascript

I don't know if this has been asked before, but what i'd like to be able to do is get data from the error console within the browser itself(if it supports it) this would be for when a user sends off a bug report it'd pull up any errors related to pages at my website for things such as typos in code and other things that somehow managed to slip by. Also, in that regard is there a way to pass the errors from the console to a useable format? If this isn't possible, then i could just tell them to copy and paste what came up from the site itself.
I thought of this right now as i was thinking about how to make the bug reporting system run better since the entire thing is basically ran within the browser and for the backend I can easily just look at error logs but for the frontend ie javascript bits of things it's not goign to be as easy.
So to finish wrap all of this up in one little statement, is there an easy way to get the data from the error console and be able to send it along via javascript ie to a form, or something similar.
You can use the onerror event in JS to get the details of the error. Hoptoad do this for example and log the errors to their console, Their code re-uses lots of nice JS scripts including a printStackTrace function that is great.....
You can see how they do it here:
http://hoptoadapp.com/javascripts/notifier.js

Categories