File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 348
348
}
349
349
} ;
350
350
351
+ /**
352
+ * Attempt to get a value from localStorage
353
+ *
354
+ * @param string key
355
+ * @return string The value obtained from localStorage, or
356
+ * undefined if localStorage is inaccessible
357
+ */
358
+ object . attemptGetSessionStorage = function ( key ) {
359
+ try {
360
+ return sessionStorage . getItem ( key ) ;
361
+ } catch ( e ) {
362
+ return null ;
363
+ }
364
+ } ;
365
+
366
+ /**
367
+ * Attempt to write a value to localStorage
368
+ *
369
+ * @param string key
370
+ * @param string value
371
+ * @return boolean Whether the operation succeeded
372
+ */
373
+ object . attemptWriteSessionStorage = function ( key , value ) {
374
+ try {
375
+ sessionStorage . setItem ( key , value ) ;
376
+ return true ;
377
+ } catch ( e ) {
378
+ return false ;
379
+ }
380
+ } ;
381
+
351
382
/**
352
383
* Finds the root domain
353
384
*/
Original file line number Diff line number Diff line change 300
300
if ( batch . length > 0 ) {
301
301
var beaconStatus ;
302
302
303
- if ( useBeacon ) {
303
+ if ( useBeacon && helpers . attemptGetSessionStorage ( 'sp_corsPreflight' ) ) {
304
304
const headers = { type : 'application/json' } ;
305
305
const blob = new Blob ( [ encloseInPayloadDataEnvelope ( attachStmToEvent ( batch ) ) ] , headers ) ;
306
306
try {
319
319
320
320
if ( ! useBeacon || ! beaconStatus ) {
321
321
xhr . send ( encloseInPayloadDataEnvelope ( attachStmToEvent ( batch ) ) ) ;
322
+ helpers . attemptWriteSessionStorage ( 'sp_corsPreflight' , true ) ;
322
323
}
323
324
}
324
325
You can’t perform that action at this time.
0 commit comments