From b3c45a107c2f9800260be829b8ccd1f1b53c970c Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Wed, 15 Mar 2023 15:54:58 -0700 Subject: [PATCH] Only patch once --- methods/flex-micro.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/methods/flex-micro.js b/methods/flex-micro.js index 6db11aa..965137f 100644 --- a/methods/flex-micro.js +++ b/methods/flex-micro.js @@ -333,25 +333,30 @@ window.SENTRY_INIT_METHODS["flex-micro"] = { } var patch_temp_queueing_handlers = function() { - window.__SENTRY_MICRO__.error_queue = []; - patch_global_handler('error', temp_queueing_patch('error')); - patch_global_handler('unhandledrejection', temp_queueing_patch('unhandledrejection')); - patch_set_callback_func(window, 'setTimeout', temp_queueing_patch('trycatch')); - patch_set_callback_func(window, 'setInterval', temp_queueing_patch('trycatch')); - patch_set_callback_func(window, 'requestAnimationFrame', temp_queueing_patch('trycatch')); - patch_xhr(temp_queueing_patch('trycatch')); - DEFAULT_EVENT_TARGET.forEach((t) => patch_event_target(t, temp_queueing_patch('trycatch'))); + if (!window.__SENTRY_MICRO__.error_queue) { + window.__SENTRY_MICRO__.error_queue = []; + patch_global_handler('error', temp_queueing_patch('error')); + patch_global_handler('unhandledrejection', temp_queueing_patch('unhandledrejection')); + patch_set_callback_func(window, 'setTimeout', temp_queueing_patch('trycatch')); + patch_set_callback_func(window, 'setInterval', temp_queueing_patch('trycatch')); + patch_set_callback_func(window, 'requestAnimationFrame', temp_queueing_patch('trycatch')); + patch_xhr(temp_queueing_patch('trycatch')); + DEFAULT_EVENT_TARGET.forEach((t) => patch_event_target(t, temp_queueing_patch('trycatch'))); + } } var patch = function() { - // these correspond to GlobalHandlers and TryCatch integrations - patch_global_handler('error', filtering_patch); - patch_global_handler('unhandledrejection', filtering_patch); - patch_set_callback_func(window, 'setTimeout', filtering_patch); - patch_set_callback_func(window, 'setInterval', filtering_patch); - patch_set_callback_func(window, 'requestAnimationFrame', filtering_patch); - patch_xhr(filtering_patch); - DEFAULT_EVENT_TARGET.forEach((t) => patch_event_target(t, filtering_patch)); + if (!window.__SENTRY_MICRO__.patched) { + window.__SENTRY_MICRO__.patched = true; + // these correspond to GlobalHandlers and TryCatch integrations + patch_global_handler('error', filtering_patch); + patch_global_handler('unhandledrejection', filtering_patch); + patch_set_callback_func(window, 'setTimeout', filtering_patch); + patch_set_callback_func(window, 'setInterval', filtering_patch); + patch_set_callback_func(window, 'requestAnimationFrame', filtering_patch); + patch_xhr(filtering_patch); + DEFAULT_EVENT_TARGET.forEach((t) => patch_event_target(t, filtering_patch)); + } } var has_DOMContentLoaded_already_fired = function() {