Sha256: 2259e953c72f858e9ea59dc0f6d793bba0890cb2203103b1288c9c40eda9ca87

Contents?: true

Size: 819 Bytes

Versions: 3

Compression:

Stored size: 819 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'] && headers['Content-Type'].include?('text/html')
        response = inject_javascript_to_response(response)
      end

      [status, headers, response]
    end

    def inject_javascript_to_response(response)
      if Raygun.configuration.js_api_key.present? && response.respond_to?('[]')
        response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
        response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
      end

      response
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
raygun4ruby-3.2.3 lib/raygun/middleware/javascript_exception_tracking.rb
raygun4ruby-3.2.3.pre lib/raygun/middleware/javascript_exception_tracking.rb
raygun4ruby-3.2.1 lib/raygun/middleware/javascript_exception_tracking.rb