feat: screenshot capture messenger#1535
Merged
Merged
Conversation
3f6f0cf to
4ed3252
Compare
Collaborator
Author
|
bugbot run |
Collaborator
Author
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts cross-window messenger functionality from
plugin-autocapture-browserinto a shared module inanalytics-core, and adds background capture support that both autocapture and session-replay can use through a single shared messenger instance.Problem
Previously,
plugin-autocapture-browserowned its ownWindowMessengerclass, which handled all cross-windowpostMessagecommunication (visual tagging, ping/pong, etc.). Background capture is a new feature that needs to be available to bothplugin-autocapture-browserandsession-replay-browser. Without a shared messenger, each plugin would attach its ownmessagelistener and load its own copy of external scripts, causing duplicate listeners, duplicate script loads, and double notifications.Solution
New
messenger/module inanalytics-core:BaseWindowMessenger— Generic, feature-agnostic cross-window messenger usingpostMessage. Handles message routing, request/response correlation (with timeouts), action handler dispatch, and idempotent script loading. The class is not exported as a value; consumers must use the singleton factory.getOrCreateWindowMessenger()— Singleton factory stored onglobalScope. A branded property (__AMPLITUDE_MESSENGER_INSTANCE__) is used instead ofinstanceoffor reliable cross-bundle identity checks. This ensures that even when autocapture and session-replay are loaded as separate bundles, they share the same messenger instance and singlemessagelistener.enableBackgroundCapture(messenger)— Composable enabler function that registers background-capture action handlers on a messenger instance. Idempotent via a brand key — safe to call from both autocapture and session-replay; only the first call takes effect.AMPLITUDE_ORIGIN,AMPLITUDE_ORIGIN_EU,AMPLITUDE_ORIGIN_STAGING) and the background capture script URL are now defined inanalytics-coreand re-exported fromplugin-autocapture-browserfor backwards compatibility.Refactored
plugin-autocapture-browser:WindowMessengerclass is replaced by anenableVisualTagging(messenger, options)function that follows the same composable pattern — it registers visual-tagging-specific action handlers on the shared messenger.autocapture-plugin.tsnow uses the singleton:getOrCreateWindowMessenger()→enableVisualTagging()→enableBackgroundCapture()→messenger.setup().messengeroption is removed fromvisualTaggingOptionssince the singleton handles this.Checklist
Note
Medium Risk
Touches cross-window messaging and dynamic script loading used by multiple plugins; mistakes could cause missed/duplicated postMessage handling or load failures across autocapture/session replay, though changes are guarded by singleton/idempotency and covered by tests.
Overview
Adds a new
analytics-coremessenger/module, exposinggetOrCreateWindowMessenger()(global singleton with branded identity), shared origin constants, and utilities for buffered action handling plus deduped external script loading.Introduces
enableBackgroundCapture()to register background-capture actions and load an external capture script once, then wires bothplugin-autocapture-browserandsession-replay-browserto use the shared messenger (including a refactor fromWindowMessengertoenableVisualTagging()and removal of thevisualTaggingOptions.messengeroption). Tests are added/updated to validate singleton behavior, message buffering/idempotency, and background capture initialization/teardown.Written by Cursor Bugbot for commit 676ae38. This will update automatically on new commits. Configure here.