MV3: Update contentscript streams x service worker logic #15952
Closed
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.
Explanation
Currently, we are keeping the service worker alive for all pages open.
Instead of always keeping the service worker alive using setInterval, we will create the interval when we know the dapp is connected to permitted accounts. This has two occurrences:
metamask_getProviderState
. To do this, we observe the request frompageChannel
to capture the chunk id. Then we observeextensionStream
to find the response with the matching chunk id because the response will not include the RPC method name.PermissionController#getPermittedAccountsByOrigin
returns accounts, then emit an event to the contentScript to create the keep alive interval.In addition:
Todo:
FIXME This is a temporary early return.
comment inresetStreamAndListeners()
.More Information
Fixes #15802
Screenshots/Screencaps
Before
After
Manual Testing Steps
Be sure to launch MV3 build:
yarn start:mv3
Verify Service Worker stays alive while dapp is connected
app-init.js
service workerVerify Service Worker stops running after in-activity if dapp is not connected
app-init.js
service workerVerify Service Worker will start up after being idle
TODO
Pre-Merge Checklist
+ If there are functional changes: