Skip to content

Conversation

@githubsven
Copy link

I noticed the events weren't working properly, so decided to have a look myself and ended up tweaking some other things.

Ended up with the following changes:

  • Split logic into classes
  • Fixed events by polling the browser storage so they work across contexts. This was broken because the background service (that triggers the event), and the contentscript (that may listen to the event) both have their own ExtPay instance, so they cannot directly communicate callbacks. This approach also removes any necessity to include ExtPay.js on extensionpay.com in the manifest.json.
  • Event listeners can now be removed.
  • Removed the need to call startBackground(); this code runs automatically when ExtPay(...) is called in the background process.
  • openLoginPage now accepts a back string parameter, that allows the user to determine the location of the "back to ..." link on the login page. The value defaults to "choose-plan" to ensure backwards compatibility, but "trial" also works and hopefully in the future you can add support for null to remove it or "plan/x" to go to specific plan immediately.

POTENTIALLY BREAKING:

  • I opted to change all Date objects to their ISO string representation, because browser.storage.set doesn't store Dates properly when they're a part of an object (saves as {} instead of as an ISO string) and because communication of Dates between contexts serializes them to string anyway. This makes communicating events between contexts more straightforward and ensures the caller always knows what they get even if ExtPay does some messaging between contexts.
  • The content script start now happens upon creation of the ExtPay object rather than upon import. If users do ExtPay(…) multiple times, then it may start multiple message event listeners (would previously also happen if the code is imported twice, but a bundler would usually prevent this).
  • Removed setting installedAt in storage, the server always returns the correct value already, so we can just use that value to prevent doing extra work.

…kground(), openLoginPage back link customization, dates are now strings
@Juliana-naey
Copy link

Great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants