Javascript Stacktrace update

本文介绍了作者自2008年启动的JavaScript堆栈跟踪项目的最新进展,包括更新后的浏览器兼容性和GitHub上的开源代码。该项目旨在为缺乏良好调试工具的浏览器提供额外的调试能力。

I started a Javascript Stacktrace project back in August 2008. The idea was to give additional debugging power to browsers where you don’t have good tools to work with. I’d like to give you an update on where the project is today.

Lately, I’ve been working on updating my old script. Since it was written, we’ve seen lots of major browser releases and the introduction of the V8 Javascript engine used byGoogle Chrome.

Updated browser compatibility

Browsers that are fully-supported and well-tested:

  1. Firefox (and Iceweasel) 0.9+
  2. UPDATE: Chrome 1+ now perfectly supported
  3. Safari 3+
  4. IE 5.5+
  5. Opera 9+
  6. Konqueror 3.5+
  7. K-Meleon 1.5.3+
  8. Epiphany 2.28.0+

Browsers that are supported in almost all cases but not as well-tested:

  1. Chrome 1+ – One bug (feature?) that may be in Chrome reporting functions as anonymous when they aren’t. HOWEVER, Chrome’s stack gives us line numbers AND column numbers, so we can see exactly where our problem is – even in minified Javascript! Sweet!Chrome 1+ now fully supported.
  2. Opera 7-8 – Opera is dead to me now. Opera 10+ has removed the error.stack info we needed and introduced error.stacktrace, but it seems very unstable. Argh.

More info about compatibility can be shown with theBrowserShots of the test suite.

Now socially coded

I’m not going to post the code here because the source and tests are now on the javascript-stacktrace project on GitHub. You can download it here.

Follow it, file bugs, and make comments there. If you have improvements to make, please fork the project and then contact me or do a “push request”. I’ll make sure you get credit ;)

UPDATE: Øyvind Sean Kinsey has added memoization (caching the implementation) for the mode and XHR bits as well as the ability to pass an existing Javascript Error and get a stacktrace. We’re working on tests and you should see project updates soon. Thanks, Øyvind!

 

var lastError;
try {
    // error producing code
} catch(e) {
   lastError = e;
   // do something else with error
}

// later...
printStackTrace({e: lastError}); //Returns stacktrace from lastError!

 

Try it out!

The code is in use on my blog. Click here to give it a spin.

 

function foo() {
    var blah;
    bar("blah");
}
 
function bar(blah) {
    var stuff;
    thing();
}
 
function thing() {
    if (true) { //your error condition here
        var st = printStackTrace();
        alert(st.join("\n\n"));
    }
}
 
foo();

 

Random note: one cool suggestion I saw was to assign printStackTrace to window.onerror. Pretty brilliant if you ask me.

I want to thank the guys who contributed to the script:Luke Smith, Loic Dachary and Johan Euphrosine.

I could use a bit of help getting the Chrome and Opera bugs worked out. I’m sure some of you guys who remember how to write software can help. Suggestions and whinings are welcome as long as they don’t get out of hand in the comments.

Javascript Stacktrace on GitHub

$ npm run start:dev1 > bigDataSearch@1.0.0 start:dev1 > cross-env REACT_APP_ENV=ctest7 webpack-dev-server --config ./config/webpack.dev.js Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme <i> [webpack-dev-server] [HPM] Proxy created: /api,/auth,/dqcdsp,/dsmetadata,/opsdsp,/scheduledsp,/searchdsp,/devdsp,/rtcp/,/resdsp,/flowdsp,/homepage,/indicatordsp,/featuredsp,/reportdsp,/easdsp,/datasync,/bigdata,/datastandarddsp,/datasecuritydsp -> http://ubsboss-ctest7.msxf.msxfyun.test building [=== ] 10% (0.0 seconds)<i> [webpack-dev-server] Project is running at: <i> [webpack-dev-server] Loopback: http://localhost:9528/ <i> [webpack-dev-server] On Your Network (IPv4): http://172.17.37.217:9528/ <i> [webpack-dev-server] Content not from webpack is served from 'E:\zkj-analytics-client\ubs-data-development-frontend\public' directory <--- Last few GCs ---> [2944:00000232F9F20080] 33192 ms: Scavenge 2019.7 (2066.1) -> 2019.2 (2076.4) MB, 4.9 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure [2944:00000232F9F20080] 33205 ms: Scavenge 2025.9 (2076.4) -> 2024.4 (2077.4) MB, 6.8 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure [2944:00000232F9F20080] 33712 ms: Scavenge 2027.0 (2077.4) -> 2025.9 (2097.9) MB, 503.4 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure <--- JS stacktrace ---> [2944:00000232F9F20080] 33192 ms: Scavenge 2019.7 (2066.1) -> 2019.2 (2076.4) MB, 4.9 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure [2944:00000232F9F20080] 33205 ms: Scavenge 2025.9 (2076.4) -> 2024.4 (2077.4) MB, 6.8 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure [2944:00000232F9F20080] 33712 ms: Scavenge 2027.0 (2077.4) -> 2025.9 (2097.9) MB, 503.4 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure <--- JS stacktrace ---> [2944:00000232F9F20080] 33205 ms: Scavenge 2025.9 (2076.4) -> 2024.4 (2077.4) MB, 6.8 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure [2944:00000232F9F20080] 33712 ms: Scavenge 2027.0 (2077.4) -> 2025.9 (2097.9) MB, 503.4 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure <--- JS stacktrace ---> [2944:00000232F9F20080] 33712 ms: Scavenge 2027.0 (2077.4) -> 2025.9 (2097.9) MB, 503.4 / 0.0 ms (average mu = 0.335, current mu = 0.193) allocation failure <--- JS stacktrace ---> re <--- JS stacktrace ---> <--- JS stacktrace ---> <--- JS stacktrace ---> <--- JS stacktrace ---> FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF75B0D151F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+121999 2: 00007FF75B05B386 DSA_meth_get_flags+64118 3: 00007FF75B05C402 DSA_meth_get_flags+68338 4: 00007FF75B992C94 v8::Isolate::ReportExternalAllocationLimitReached+116 5: 00007FF75B97D25D v8::SharedArrayBuffer::Externalize+781 6: 00007FF75B82081C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468 7: 00007FF75B81D934 v8::internal::Heap::CollectGarbage+4244 8: 00007FF75B81B2B0 v8::internal::Heap::AllocateExternalBackingStore+2000 9: 00007FF75B83FE36 v8::internal::Factory::NewFillerObject+214 10: 00007FF75B572545 v8::internal::DateCache::Weekday+1797 11: 00007FF75BA20971 v8::internal::SetupIsolateDelegate::SetupHeap+494417 12: 00000232807CD765
11-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值