Keychainify on direct access to a SteemConnect URL

in #utopian-io9 months ago (edited)

View this post on Hive: Keychainify on direct access to a SteemConnect URL


Repository & PR

https://github.com/MattyIce/steem-keychain
https://github.com/MattyIce/steem-keychain/pull/112

Context

Last week I described Keychainify, a feature I added to Steem Keychain to trigger a Keychain operation on click on a Steem Connect link on a page. But that would not work if the user copied and pasted the Steem Connect URL and loaded it directly in a browser tab or in cases such as the page using some programmatic way to redirect the user. Well, today's PR should solve the issue.

New Features

Previously, the Keychain extension was injecting what we call a content script into the source code of loaded page. That content script is what parses the source for Steem Connect anchor tags. For a direct access to be detected, I needed to modify the background script which is always running during the lifetime of a browser.

As the content script and background scripts are going to share common logic, I ended up creating a Keychainify library to avoid code duplication.

In the background script, the core of the changes is this block of code:
Screen Shot 2019-07-09 at 8.11.49 am.jpg

What is does is create an event handler to be triggered every time a browser tab is getting update (change of URL). It would then grab the new URL and Keychainify it if it is a supported Steem Connect URL.

All the rest in the PR is just code refactor and re-organisation.

GitHub Account

https://github.com/quochuy

Sort:  

Thank you for your contribution!.

  1. L74 which could be refactored using Array.includes
  2. We probably can rewrite Promise as async/await see here
  3. I prefer string.includes over string.indexOf()===-1

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thanks @justyy
I prefer using indexOf() in cases like here for more compatibility. As for async/await, my function calls another one that uses callbacks so using Promises makes it easier for calling resolve/reject

Thank you for your review, @justyy! Keep up the good work!

Running in the background forever won’t eat too many resources?

Posted using Partiko iOS

Most Chrome browser extensions have a background script that runs all the time. Chrome manages them though so they should be woken up when needed only. And for Keychain, there was already an existing background script, I just added an extra logic that the browser will trigger when a URL is loaded or has changed, in other cases it won’t do anything.

Posted using Partiko iOS

If you are curious about this, you can open a new Chrome browser tab to this address chrome://extensions/
It will list all extension you have downloaded into your browser. Then from the top right corner of the screen you should see a toggle button saying "Developer mode", toggle it on, from then, all extensions should show their ID and the ones that has a background script will have a link that says "Inspect views background page"

Hi @quochuy!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hi, @quochuy!

You just got a 0.89% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hey, @quochuy!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!