Use x_user_agent cookie for platform detection in Hotwire Native
Turbo's offline/service worker sets an x_user_agent cookie with the original browser user agent. This ensures platform detection works correctly for Hotwire Native apps where service worker requests may not carry the overridden user agent header.
This commit is contained in:
committed by
Rosa Gutierrez
parent
8c2318e267
commit
66039c92f3
@@ -0,0 +1,21 @@
|
||||
require "test_helper"
|
||||
|
||||
class SetPlatformTest < ActionDispatch::IntegrationTest
|
||||
DESKTOP_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
NATIVE_IOS_UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Hotwire Native iOS/1.0"
|
||||
|
||||
test "uses the request user agent by default" do
|
||||
sign_in_as :david
|
||||
|
||||
get board_path(boards(:writebook)), headers: { "User-Agent" => DESKTOP_UA }
|
||||
assert_match 'data-platform="desktop web"', response.body
|
||||
end
|
||||
|
||||
test "prefers x_user_agent cookie over request user agent" do
|
||||
sign_in_as :david
|
||||
|
||||
cookies[:x_user_agent] = NATIVE_IOS_UA
|
||||
get board_path(boards(:writebook)), headers: { "User-Agent" => DESKTOP_UA }
|
||||
assert_match 'data-platform="native ios"', response.body
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user