@@ -65,32 +65,33 @@ const IS_SERVICE_WORKER_ENV =
6565 typeof ServiceWorkerGlobalScope !== 'undefined' && HAS_SELF && self instanceof ServiceWorkerGlobalScope ;
6666
6767/**
68- * Check if the current environment is Safari browser.
69- * Works in both browser and web worker contexts.
70- * @returns {boolean } Whether the current environment is Safari.
68+ * Check whether the current environment is a Safari browser older than version 26 (Safari >= 26 enables WebGPU by default).
69+ * @returns {boolean } Whether the current environment is Safari older than version 26.
7170 */
72- const isSafari = ( ) => {
73- // Check if we're in a browser environment
71+ const isSafariBelow26 = ( ) => {
7472 if ( typeof navigator === 'undefined' ) {
7573 return false ;
7674 }
7775
7876 const userAgent = navigator . userAgent ;
79- const vendor = navigator . vendor || '' ;
8077
81- // Safari has "Apple" in vendor string
82- const isAppleVendor = vendor . indexOf ( 'Apple' ) > - 1 ;
83-
84- // Exclude Chrome on iOS (CriOS), Firefox on iOS (FxiOS),
85- // Edge on iOS (EdgiOS), and other browsers
86- const notOtherBrowser =
78+ // Safari has "Apple" in its vendor string. Exclude Chrome on iOS (CriOS),
79+ // Firefox on iOS (FxiOS), Edge on iOS (EdgiOS), and other browsers.
80+ const isSafari =
81+ ( navigator . vendor || '' ) . indexOf ( 'Apple' ) > - 1 &&
8782 ! userAgent . match ( / C r i O S | F x i O S | E d g i O S | O P i O S | m e r c u r y | b r a v e / i) &&
8883 ! userAgent . includes ( 'Chrome' ) &&
8984 ! userAgent . includes ( 'Android' ) ;
85+ if ( ! isSafari ) {
86+ return false ;
87+ }
9088
91- return isAppleVendor && notOtherBrowser ;
89+ // Safari reports its version via the "Version/<major>.<minor>" token in the user agent.
90+ // If the version is missing/unparseable, assume a modern Safari (i.e. not below 26).
91+ const match = userAgent . match ( / V e r s i o n \/ ( \d + ) / ) ;
92+ return match ? parseInt ( match [ 1 ] , 10 ) < 26 : false ;
9293} ;
93- const IS_SAFARI = isSafari ( ) ;
94+ const IS_SAFARI_BELOW_26 = isSafariBelow26 ( ) ;
9495
9596/**
9697 * A read-only object containing information about the APIs available in the current environment.
@@ -120,8 +121,8 @@ export const apis = Object.freeze({
120121 /** Whether the WebNN API is available */
121122 IS_WEBNN_AVAILABLE ,
122123
123- /** Whether we are running in a Safari browser */
124- IS_SAFARI ,
124+ /** Whether we are running in a Safari browser older than version 26. */
125+ IS_SAFARI_BELOW_26 ,
125126
126127 /** Whether the Node.js process API is available */
127128 IS_PROCESS_AVAILABLE ,
0 commit comments