Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect safari when launching from dock #1356

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/compat/browser_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,23 @@ let isPlayStation5 = false;
{
isSafariMobile = true;
} else if (
// the following statement check if the window.safari contains the method
// "pushNotification", this condition is not met when using web app from the dock
// on macOS, this is why we also check userAgent.
Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor") >= 0 ||
(window as ISafariWindowObject).safari?.pushNotification?.toString() ===
"[object SafariRemoteNotification]"
"[object SafariRemoteNotification]" ||
// browsers are lying: Chrome reports both as Chrome and Safari in user
// agent string, So to detect Safari we have to check for the Safari string
// and the absence of the Chrome string
// eslint-disable-next-line max-len
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#which_part_of_the_user_agent_contains_the_information_you_are_looking_for
((/Safari\/(\d+)/).test(navigator.userAgent) &&
// Safari should contain Version/ in userAgent
(/Version\/(\d+)/).test(navigator.userAgent) &&
(navigator.vendor?.indexOf("Apple") !== -1) &&
!(/Chrome\/(\d+)/).test(navigator.userAgent) &&
!(/Chromium\/(\d+)/).test(navigator.userAgent))
) {
isSafariDesktop = true;
}
Expand Down
Loading