Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:54:30+00:00 2026-05-24T08:54:30+00:00

I want to be able to send myself all the javascript errors on a

  • 0

I want to be able to send myself all the javascript errors on a page. I am an extension developer, so the following has an emphasis on making sure the dom is ready before making calls to it.

I investigated adding some functionality to the throw to also send or mail the exceptions, but I didn’t find this to be possible.

1:main solution to this, a window.onerror handler:

window.onerror = function(e, url, line){
  mailError('onerror: ' + e + ' URL:' + url + ' Line:' + line);
  console.error('\nLine ' + line + ':');
  setTimeout(function(){retry();}, 100); //mainly useful in content scripts for extensions, 
  return true; 
}

May also need to do same thing via jQuery:

$(window).error( 
  function(e, url, line){
    //handle error
  }
);

The downfall of this is that your code has stopped executing.

To avoid errors stopping execution, it’s best to use callbacks to make sure code executes in a certain sequence, and to utilize events wherever possible. You can also protect dom calls with a few techniques

$(document).ready({
  //you usually won't get bad dom calls wrapping your code in this
});

You can also consider running code on window.onload

window.onload = function(){
  //you page will probably twitch upon executing code at this time
  //but you will almost never have a bad dom call
};

Another technique

if (document.getElementById('iNeedThisElement')) {
  //doin work!
  document.getElementById('iNeedThisElement').style.display = 'block';
} else {
  var stillNeedToTakeCareOfX = true; //false otherwise since it's undefined
  mailError('iNeedThisElement was unavailable...');
}

Using these techniques and just debugging your application, you should be fairly well off. Since console.error, .warn, and .log statements cannot be retrieved and reported back to your, a small alternative suite is provided below:

var Xe = { }; //Extreme error suite

function extraInfo(e){
   //e optional
   if(!e)e = true;

   //add an extra debug info, such as navigator or current URL
   return ' currentURL: '+ document.URL + 
        '\n userAgent: ' + navigator.userAgent + 
        '\n platform: '  + navigator.platform + 
        '\n userid: '    + localStorage.userid + 
        '\n language: '  + navigator.langauge + 
        '\n cookies?: '  + navigator.cookiesEnabled;
}

Xe.error = function(e){
  console.error(e); //maintain original functionality
  mailError('Xe err: ' + e + extraInfo() );
}


Xe.warn = function(e){
  console.warn(e);
  mailError('Xe warn: ' + e + extraInfo() );
}


Xe.log = function(e){
  console.log(e);
  mailError('Xe log: ' + e + extraInfo() );
}

As a last ditch, you can continually attempt to execute a chunk of code until it executes without errors. This is “2” below.

2:group code in large chunks and attempting to re-execute x seconds later after catching an error, or continue to next chunk of code

//defExe = DEFinitely EXEcute this code
  //functionArg, reference to a function holding a large chunk of code
  //seconds, timeout in milliseconds to re-attempt error free execution of this function
function defExe(functionArg, seconds) {
  //seconds is optional
  if (!seconds)seconds = 300;

  try {
    functionArg();
  } catch(e) {
    //mail the error plus extra info
    mailError('caught ' + e + ' attempting to re-execute ' + functionArg.name + ' in ' + seconds + ' milliseconds');

    //re-attempt to execute this code
    setTimeout(function(){ 
       defExe(functionArg, seconds); 
    }, seconds);
  }
}

this it is then used like

//array to group function chunks
var fn = [ ];

fn[1] = function (){
  //a large chunk of javascript
}
defExe(fn[1]);

fn[2] = function(){
  //another chunk of your program
}
defExe(fn[2]);

#2 Summary: Group code in functions and run in try-catch block, repeating if an errors are caught

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:54:31+00:00Added an answer on May 24, 2026 at 8:54 am

    I have mine working with window.onerror and it doesn’t stop my javascript:

    window.onerror = function(error, url, line) {
        controller.sendLog({acc:'error', data:'ERR:'+error+' URL:'+url+' L:'+line});
    };
    

    Note that controller.sendLog is a function that sends this data to a logging php.

    Can be because you’re causing some javascript error inside that function?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to send all the selected values from a listbox
I want to be able to send a parameter to a php page that
I want to be able to send e-mail from my own domain (Domain.com) over
I want to be able to send JSON as opposed to the standard QueryStrings
I want to be able to send the text on the clipboard, in Windows,
I want a PHP to be able to send 1 of 3 images, depending
In my application, I want to be able to send email. I am able
The subject of the post says it all: I want to be able to
I want to be able to send already-signed-in-users somewhere else when they go to
I want to be able to send a password reset email using django.contrib.auth.views.password_reset but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.