Coder Social home page Coder Social logo

Comments (14)

iainbeeston avatar iainbeeston commented on August 11, 2024

How about something like this? (Uses callbacks to avoid the need for passing params)

https://gist.github.com/b225fc3566e4adcc241a

from airbrake-js.

benarent avatar benarent commented on August 11, 2024

Hi @iainbeeston I'm open, and I welcome a pull request. Would you be able to show in a demo? View source of blog.airbrake.io/js-test/ for a demo (Note: This has a ton of alpha and other funky stuff)

from airbrake-js.

iainbeeston avatar iainbeeston commented on August 11, 2024

How about this? http://www.iainbeeston.com/airbrake-test.html (I'm getting xss errors though using the same airbrake credentials as the original blog page)

from airbrake-js.

benarent avatar benarent commented on August 11, 2024

Hi @iainbeeston . Hit me up on IM, [email protected] I need to make a few tweaks, but I've a notifier that works.

from airbrake-js.

bluesmoon avatar bluesmoon commented on August 11, 2024

Rather than a simple asynchronous load, I'd suggest going into full non-blocking mode so that server/CDN failure does not block the hosting page from loading. Method described here: http://calendar.perfplanet.com/2012/the-non-blocking-script-loader-pattern/

from airbrake-js.

vmihailenco avatar vmihailenco commented on August 11, 2024

@duncanbeevers , can you please look at this?

from airbrake-js.

duncanbeevers avatar duncanbeevers commented on August 11, 2024

I personally prefer relying on the browser's handling of the defer attribute, though we should probably add the async attribute as well. As it stands, all the inline code directly addresses creating a shim notifier implementation and not at all with browser-quirks gymnastics.

Anyone else care to weigh in on this?

from airbrake-js.

bluesmoon avatar bluesmoon commented on August 11, 2024

neither defer nor async will prevent blocking the onload handler. If the server your script is on goes down, this will cause the host page to not complete loading. I'm not sure too many site owners like adding another SPOF to their site, especially one that they cannot control.

The technique I've described above takes you out of the loading queue so that failures in your infrastructure do not affect your customers. It is more effort, but ultimately it's about being a responsible third party.

from airbrake-js.

duncanbeevers avatar duncanbeevers commented on August 11, 2024

The FIF technique requires quite a lot of inline code. @benarent @vmihailenco What do you think of just registering a hook onto window.onload and pulling down the notifier after everything else? Something like this:

// Setup shim
window.Airbrake = [];
window.Airbrake.wrap = function(fn) { return function() {
  try { return fn.apply(this, arguments); }
  catch (exc) { Airbrake.push({error: exc}); throw exc; } }; };
// Invoke script-loader
(function() {
  // We'll do this once the page's onload has fired
  function get() {
    var s = document.createElement('script'),
        p = document.getElementsByTagName('script')[0];
    s.src = 'https://ssljscdn.airbrake.io/airbrake-js-tracekit-sourcemap.min.js';
    p.parentNode.insertBefore(s, p);
  }
  // Attach event handler to window onload
  if (window.addEventListener) { window.addEventListener('load', get, false); }
  } else { window.attachEvent('onload', get); }
}());

from airbrake-js.

bluesmoon avatar bluesmoon commented on August 11, 2024

That works too, but then you won't capture errors that happen before onload fires.

from airbrake-js.

benarent avatar benarent commented on August 11, 2024

@duncanbeevers I'm not 100% on this. I'll leave it to you.

from airbrake-js.

duncanbeevers avatar duncanbeevers commented on August 11, 2024

Fortunately the shim implementation can capture and queue up errors that
are later processed by the full implementation.
On Nov 18, 2013 4:01 PM, "Philip Tellis" [email protected] wrote:

That works too, but then you won't capture errors that happen before
onload fires.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-28742523
.

from airbrake-js.

vmihailenco avatar vmihailenco commented on August 11, 2024

SGTM.

Can I ask you to not "compact" code like that? You hardly save 50 bytes, but reading such code is complicated.

from airbrake-js.

duncanbeevers avatar duncanbeevers commented on August 11, 2024

Addressed by e2629e6

from airbrake-js.

Related Issues (20)

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.