Giter Site home page Giter Site logo

badjs's Introduction

badjs

以下均是在chrome最新版本可行,其他浏览器未测试过

1.运行时报错 window.addEventListener('error', function (errorEvent) { const { message, filename, lineno, colno, error } = errorEvent;

console.log('message', message); // 错误信息
console.log('filename', filename); // 发生错误的脚本url
console.log('lineno', lineno); // 错误行
console.log('colno', colno);//错误列
console.log('error', error); // Error对象, 错误stack

});

2.ie8以下不支持eventListener window.onerror();

3.跨域同步错误 1). crossorigin="anonymous" Access-Control-Allow-Origin: * 2).跨域 crossorigin="use-credentials" Access-Control-Allow-Origin: 具体域Access-Control-Allow-Credentials: true

3).

try{
      test(); //跨域方法
  } catch(error) {
      console.log('error', error);
      throw(error);
  }

4.跨域异步函数使用trycatch包裹,catch中自行上报(可以使用打包工具自动添加try catch)

5.未捕获的promise reject (同域跨域均可) window.addEventListener('unhandledrejection', function (errorEvent) { console.log('unhandledrejectionmessage', errorEvent.reason); // 错误信息 });

6.资源加载错误,和运行时错误方式一样,但是需要在回调中判断来源(link、script) performance.getEntries() 和onload 配合使用的方式有瑕疵(异步script不行) window.addEventListener('error',function(){})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.