File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ import {
43
43
getJsSdkLibrary ,
44
44
wasShopperInsightsUsed ,
45
45
isPayPalTrustedUrl ,
46
+ getSDKInitTime ,
46
47
} from "@paypal/sdk-client/src" ;
47
48
import {
48
49
rememberFunding ,
@@ -1067,6 +1068,47 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
1067
1068
queryParam : true ,
1068
1069
} ,
1069
1070
1071
+ sdkInitTimings : {
1072
+ type : "object" ,
1073
+ queryParam : false ,
1074
+ required : false ,
1075
+ value : ( ) => {
1076
+ // eslint-disable-next-line compat/compat
1077
+ const sdkScript = window ?. performance
1078
+ ?. getEntriesByType ( "resource" )
1079
+ // eslint-disable-next-line security/detect-unsafe-regex
1080
+ . find ( ( { name } ) => / p a y p a l \. c o m (?: : \d + ) ? \/ s d k \/ j s / . test ( name ) ) ;
1081
+
1082
+ const isCached = ( performanceEntry ) => {
1083
+ if (
1084
+ ! performanceEntry ||
1085
+ typeof performanceEntry . duration === "undefined"
1086
+ ) {
1087
+ return "unknown" ;
1088
+ }
1089
+
1090
+ return performanceEntry . duration === 0 ? "yes" : "no" ;
1091
+ } ;
1092
+
1093
+ let sdkInitTimeStamp ;
1094
+
1095
+ // this technically isn't possible with the way paypal-sdk-client
1096
+ // is set up but one day it could be refactored and this would throw
1097
+ // an error and block the button from rendering
1098
+ try {
1099
+ sdkInitTimeStamp = getSDKInitTime ( ) ;
1100
+ } catch ( error ) {
1101
+ // do nothing
1102
+ }
1103
+
1104
+ return {
1105
+ sdkInitTimeStamp,
1106
+ sdkScriptDownloadDuration : sdkScript ?. duration ,
1107
+ isSdkCached : isCached ( sdkScript ) ,
1108
+ } ;
1109
+ } ,
1110
+ } ,
1111
+
1070
1112
sdkMeta : {
1071
1113
type : "string" ,
1072
1114
queryParam : true ,
You can’t perform that action at this time.
0 commit comments