Only inject `hook.js` script for Firefox. Use ExecutionWorld.MAIN for Chrome
Fixes #1162
This is a revival of https://github.com/apollographql/apollo-client-devtools/pull/1164 with some tweaks. Now that we are running Chrome on Manifest v3, we are able to use hook.js as a content script using ExecutionWorld.MAIN. Unfortunately this is not yet supported in Firefox, so we have to rely on script injection for this to work. The script injection used in #1164 is now added back, but only when building for Firefox.
This looks good to me (tested locally in Chrome and Firefox), but I'm slightly concerned: didn't you see the extension break with the current Firefox code, in Firefox?
Could you reproduce that?
Talked in our 1:1. Posting the answer here for transparency:
I feel a bit more confident now in this change for a couple reasons:
- We now unconditionally show the devtools where before we relied on a message sent to devtools before the panel was created (https://github.com/apollographql/apollo-client-devtools/pull/1220)
- Message passing has been reworked for stability (https://github.com/apollographql/apollo-client-devtools/pull/1226)
- The injection mechanism is now relegated to Firefox only now that Chrome is on manifest v3 (https://github.com/apollographql/apollo-client-devtools/pull/1225)
We are going to wait to merge this for a few days after 4.7.0 goes out to ensure we catch any bugs or new issues that arise from that release.
Putting in draft for now to avoid accidental merge until we are ready.
So far we've seen no reports that the latest update caused any more issues. I'll go ahead and merge this and get a release out tomorrow.