百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

spectator_sport

> 编程语言
开源

在自主托管的 Rails 引擎中记录和重放浏览器会话。

195 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

在自主托管的 Rails 引擎中记录和重放浏览器会话。

Spectator Sport

Record and replay browser sessions in a self-hosted Rails Engine.

Spectator Sport uses the rrweb library to create recordings of your website's DOM as your users interact with it. These recordings are stored in your database for replay by developers and administrators to analyze user behavior, reproduce bugs, and make building for the web more fun.

This gem is very early in its development lifecycle and will undergo significant changes on its journey to v1.0. I would love your feedback and help in co-developing it, just fyi that it's going to be so much better than it is right now.

Future Roadmap:

  • ✅ Proof of concept and technical demo
  • ✅ Running in production on Ben Sheldon's personal business websites
  • ✅ Publish manifesto of principles and intent
  • ◻️ Reliable and efficient event stream transport
  • ✅ Player dashboard design using Bootstrap and Turbo (#20)
  • ◻️ Automatic cleanup of old recordings to minimize database space
  • ◻️ Identity methods for linking application users to recordings
  • ◻️ Privacy controls with masked recording by default
  • ◻️ Automated installation process with Rails generators
  • ◻️ Fully documented installation process
  • Release v1.0
  • ◻️ Live streaming replay of recordings
  • ◻️ Searching / filtering of recordings, including navigation and 404s/500s, button clicks, rage clicks, dead clicks, etc.
  • ◻️ Custom events
  • Your feedback and ideas. Please open an Issue or Discussion or even a PR modifying this Roadmap. I'd love to chat!

Installation

The Spectator Sport gem is conceptually two parts packaged together in this single gem and mounted in your application:

  1. The Recorder, including javascript that runs in the client browser and produces a stream of events, an API endpoint to receive those events, and database migrations and models to store the events as a cohesive recording.
  2. The Player Dashboard, an administrative dashboard to view and replay stored recordings

To install Spectator Sport in your Rails application:

  1. Add spectator_sport to your application's Gemfile and install the gem:
    bash
    bundle add spectator_sport
  2. Install Spectator Sport in your application. _ This will change on the path to v1._ Explore the /demo app as live example:
    • Create database migrations with bin/rails spectator_sport:install:migrations. Apply migrations with bin/rails db:prepare

    • Mount the recorder API in your application's routes:

      ruby
      # config/routes.rb
      mount SpectatorSport::Engine, at: "/spectator_sport"
    • Add the spectator_sport_script_tags helper to the bottom of the `` of layout/application.rb. Example:

      erb
      
        
        
      

      If the engine is mounted with a different as: option or within a namespace, pass the route name it is mounted as. For example, namespace(:admin) { mount SpectatorSport::Engine, at: "/spectator_sport" } is mounted as admin_spectator_sport:

      erb
    • Add a `

  3. To view recordings, mount the Player Dashboard in your application's routes and set up authorization to limit access to it. See Dashboard authorization for route-constraint, Basic Auth, and ActiveSupport.on_load initializer examples:
    ruby
    # config/routes.rb
    mount SpectatorSport::Dashboard::Engine, at: "/spectator_sport_dashboard", as: :spectator_sport_dashboard

Labeling recordings

You can associate key-value labels with the current recording by calling spectator_sport_label_recording in any template:

erb

…

erb

…

ruby
# config/routes.rb
authenticate :user, ->(user) { user.admin? } do
  mount SpectatorSport::Dashboard::Engine, at: 'spectator_sport_dashboard', as: :spectator_sport_dashboard
end

Or set up Basic Auth:

ruby
# config/initializers/spectator_sport.rb
SpectatorSport::Dashboard::Engine.middleware.use(Rack::Auth::Basic) do |username, password|
  ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.spectator_sport_username, username) &
  ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.spectator_sport_password, password)
end

If you are using an authentication method similar to the one used in ONCE products, you can utilize an auth constraint in your routes.

ruby
# config/routes.rb
class AuthRouteConstraint
  def matches?(request)
    return false unless request.session[:user_id]
    user = User.find(request.session[:user_id])
 
    if user && user.admin?
      cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
      token = cookies.signed[:session_token]
 
      return user.sessions.find_by(token: token)
    end
  end
end

Rails.application.routes.draw do
  # ...
  namespace :admin, constraints: AuthRouteConstraint.new do
    mount SpectatorSport::Dashboard::Engine, at: 'spectator_sport_dashboard', as: :spectator_sport_dashboard
  end
end

Or extend the SpectatorSport::Dashboard::ApplicationController with your own authorization logic. The controller runs the :spectator_sport_dashboard_application_controller load hook, so you can include your application's own authentication concerns and add before_action checks from an initializer:

ruby
# config/initializers/spectator_sport.rb
ActiveSupport.on_load(:spectator_sport_dashboard_application_controller) do
  # context here is SpectatorSport::Dashboard::ApplicationController

  # include Authentication # e.g. concerns from your application

  before_action do
    raise ActionController::RoutingError.new('Not Found') unless current_user&.admin?
  end

  def current_user
    # load current user from session, cookies, etc.
  end
end

Contributing

Please don't be shy about opening an issue or half-baked PR. Your ideas and suggestions are more important to discuss than a polished/complete code change.

This repository is intended to be simple and easy to run locally with a fully-featured demo application for immediately seeing the results of your proposed changes:

bash
# 1. Clone this repository via git
# 2. Set it up locally
bundle install
# 3. Create database
bin/rails db:setup
# 4. Run the demo Rails application:
bin/rails s
# 5. Load the demo application in your browser
open http://localhost:3000
# 6. Make changes, see the result, commit and make a PR!

Releasing a new version

  1. Update the version in lib/spectator_sport/version.rb
  2. Run bundle install to update Gemfile.lock
  3. Commit the version bump and updated Gemfile.lock:
    bash
    git add lib/spectator_sport/version.rb Gemfile.lock
    git commit -m "Bump version to x.y.z"
  4. Build and publish to RubyGems, tag, and push to GitHub:
    bash
    bundle exec rake release
  5. Create a GitHub Release at https://github.com/bensheldon/spectator_sport/releases using the new vx.y.z tag.

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言