-
Notifications
You must be signed in to change notification settings - Fork 172
feat: add iframe support for Apollo Client detection #1797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
#1764 Bundle Size — 2.01MiB (+0.07%).26712e0(current) vs 8961f38 main#1758(baseline) Warning Bundle contains 14 duplicate packages – View duplicate packages Bundle metrics
Bundle size by type
Bundle analysis report Branch feat/iframe-support Project dashboard Generated by RelativeCI Documentation Report issue |
commit: |
| port.onDisconnect.addListener(() => { | ||
| ports[tabId].disconnectPorts?.(); | ||
| ports[tabId].tab = null; | ||
| ports[tabId].tabPorts.delete(port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self to dive in a bit deeper tomorrow:
I wonder if there is a chance to use the frameId as part of this identifier instead of using a Set. The idea is that if we can beef up the id a bit more, hopefully that would simplify some of the handling in other places where we don't have to try and ignore some messages due to it broadcasting to all frames on the same tab ID.
aff9c7d to
26712e0
Compare
Summary
This PR enables
apollo-client-devtoolsto detect and interact with Apollo Clients running inside same-origin iframes, in addition to the main window.Problem
Previously we only detected clients in the top-level window. If a page had iframes with their own Apollo Client instances, those clients were invisible to the extension.
Solution
all_frames: trueto content scripts sotab.jsandhook.jsrun in every frame (main window + iframes)background.tsfrom tracking a singletabport per tab to aMap<tabPorts, frameId>per tab, enabling multiple frames to connect while tracking which frame each port belongs toclientFrames: Map<clientId, frameId>to track which Apollo Client belongs to which frame, enabling targeted message routinggetClientshandler inhook.tsusesSKIP_RESPONSEso frames without Apollo Clients don't pollute discovery responsesFiles Changed
all_frames: trueall_frames: trueSKIP_RESPONSEsymbol + handler logic to skip sending responsesSet<tabPorts>-->Map<Port, frameId>, addclientFramesmapping, implement targeted routingSKIP_RESPONSEtogetClientshandler for frames without clientsAutomated Tests Added
Two new unit tests in
src/extension/__tests__/rpc.test.ts:does not send response when handler returns SKIP_RESPONSESKIP_RESPONSE, no RPC response message is postedSKIP_RESPONSE allows handler to be re-registered after unsubscribeSKIP_RESPONSEcan be properly unsubscribed and re-registeredManual Verification Steps
Single frame (regression test)
Multi-frame detection
npm run start:devnpm run chromehttp://localhost:3000Targeted routing verification
frameIdin console logs in dev mode)Limitations
all_frames: trueonly works for same-origin iframes. Cross-origin iframes remain invisible.References