-
Notifications
You must be signed in to change notification settings - Fork 418
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
Fix: ensure the service worker is awake before every port message #1433
Conversation
Overall, really solid stuff. Thanks so much - I see just the failing tests - and once that is resolved this can go in! |
@TarikGul I tried to fix that test and I'm honestly struggling to figure out how to get it to work. It won't let me mock an implementation of |
Would love to help out on it! I'll have a look :) |
The error comes from https://github.com/polkadot-js/dev/blob/master/packages/dev-test/src/env/expect.ts#L92-L102 which is part of I looked into to this for an hour or so, and will get back to it soon, but some things to note:
|
@F-OBrien the issue seems to be the test requires the background script to respond with |
To add to this too |
Yes, that's why I was trying to mock The test framework seems quite custom so I'm not exactly clear what the options are. I was thinking I could try use to use Sinon rather than jest to fake functions that use the chrome api it instead to see if we can get that to work. Ideally we'd like to be able to test as much of the code as possible without mocks. |
@TarikGul this took me way to long to figure out but I've finally got the test to pass. I needed to create a object to wrap |
@Juanma0x I believe it should |
Brilliant! You're amazing thanks so much for this - this was pretty critical, hats off to you! Once this goes in I will bump the PJS deps as all the upstream repos have been updated, then we can go ahead and release this and push it to the store. |
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.
lgtm 🚀
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This builds on the approach taken in #1424 but instead of only doing it once when opening the popup it does it before any message over a port from either the extension UI or content script. This prevents attempting to send message over disconnected ports or while the service worker is idle or terminated and should hopefully close multiple open issues including #1432, #1420, #1417, #1416, #1415.
This PR does not add a heartbeat to the service worker so if there are transactions that may take a long time to return it is still possible the service worker may timeout and become idle however I've not seen instance of this from my testing as when connected to a dApp there is a ping message being sent every 5 seconds.
secondly I added a check filter out non http url when setting an active tab as the stripUrl function was always erroring for pages like browser tabs like chrome://newtab/ and removed a WINDOW console log which appeared to have been left in when debugging.
@TarikGul