Sha256: 84a167d26171ec4163d667add22581891a208b0b2caafa6f3966bb4372be7e19

Contents?: true

Size: 698 Bytes

Versions: 1

Compression:

Stored size: 698 Bytes

Contents

module Raygun::Middleware
  class JavascriptExceptionTracking
    def initialize(app)
      @app = app
    end

    def call(env)
      status, headers, response = @app.call(env)

      # It's a html file, inject our JS
      if headers['Content-Type'].include?('text/html')
        response = inject_javascript_to_response(response)
      end

      [status, headers, response]
    end

    def inject_javascript_to_response(response)
      response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
      response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")

      response
    end

    private
    def js_tracker
      @js_tracker = Raygun::JavaScriptTracker.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raygun4ruby-3.1.0 lib/raygun/middleware/javascript_exception_tracking.rb