Skip to content
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

feat: MV3 boilerplate #1044

Closed
wants to merge 27 commits into from
Closed

feat: MV3 boilerplate #1044

wants to merge 27 commits into from

Conversation

meandavejustice
Copy link
Collaborator

This is the starting point for Manifest v3 extension.

What currently works?

  • simple redirects from ipfs.io and dweb links.
  • dnslink urls are fetched and added to the DeclarativeNetRequest api ruleset for redirection.
  • added workflow to start testing out CI
  • add typescript
  • add prettier
  • add eslint
  • building with esbuild for ⚡ fast builds
  • adds boilerplate for popup

All of this is in /mv3

cc/ @lidel

- adds mv3/ directory
- setup fast builds with esbuild
- setup prettier for formatting
- setup eslint
- setup typescript
- adds BASIC handling of ipfs.io & dweb.link URLs to local node via
declarativeNetRequest api (manifest v3)
- adds BASIC handling of DNSLink requests by parsing, talking to local
node via ipfs-http-client, and adding rule to declarativeNetRequest
ruleset
- adds boilerplate for popup
@ipfs ipfs deleted a comment from welcome bot Jan 25, 2022
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Small asks before we merge (inline)

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
mv3/addon/background.ts Outdated Show resolved Hide resolved
mv3/addon/background.ts Outdated Show resolved Hide resolved
mv3/addon/background.ts Outdated Show resolved Hide resolved
mv3/package.json Outdated Show resolved Hide resolved
mv3/package.json Outdated Show resolved Hide resolved
mv3/package.json Outdated Show resolved Hide resolved
mv3/addon/background.ts Outdated Show resolved Hide resolved
@meandavejustice
Copy link
Collaborator Author

@lidel Comments addressed 👍

@meandavejustice
Copy link
Collaborator Author

@lidel Could I get yours 👀 on this again? Thanks!

@lidel lidel requested review from lidel and removed request for lidel February 19, 2022 02:51
- adds mv3/ directory
- setup fast builds with esbuild
- setup prettier for formatting
- setup eslint
- setup typescript
- adds BASIC handling of ipfs.io & dweb.link URLs to local node via
declarativeNetRequest api (manifest v3)
- adds BASIC handling of DNSLink requests by parsing, talking to local
node via ipfs-http-client, and adding rule to declarativeNetRequest
ruleset
- adds boilerplate for popup
- add welcome page
- add options page
- add clipboard functionality
- add status updates to popup
- add basic UI styling to popup
- on installed checks
- on uninstalled checks
- runtime checks
- options/state cleanup
- add firefox request handling for when they support mv3
@lidel lidel mentioned this pull request Mar 25, 2022
@lidel lidel changed the title MV3 Extension boilerplate feat: MV3 boilerplate Mar 28, 2022
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @meandavejustice, and apologies for late review.

Dynamic rules are pretty powerful, and I think we should be able to live with them as long we add proper cache around their creation.

Left some feedback below:

  • ⚠️ important things we should fix
    • lmk if you prefer to do them in this PR or merge as-is and track them in separate issues
  • 💭 lower priority thoughts on style and nice-to-haves

mv3/addon/background.ts Outdated Show resolved Hide resolved
mv3/addon/background.ts Outdated Show resolved Hide resolved
return url.includes("chrome://");
}

async function resolveDNSAndAddRule(domain) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 can we make resolveDNSAndAddRule return boolean to indicate if companion added a new rule or not?
That way, we could act on that hint in places like retryOnTabUpdate and reload impacted tabs immediately (find all tabs with URL matching the added rule and reload them fast enough that the user does not even see the original URL).

mv3/addon/background.ts Outdated Show resolved Hide resolved
priority: 1,
action: {
type: "redirect",
redirect: { url: `https://dweb.link${contentPath}` },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This needs additional tweak to stay on /ipns/ namespace (we don't want users to be redirected to status snapshot and lose future updates).

Assuming example.com has a valid dnslink pointing at /ipfs/{cid}

Opening https://example.com/foo/bar?arg=a#buzz should redirect to
https://dweb.link/ipns/example.com/foo/bar?arg=a#buzz.

(We want to preserve all params, simply replace https?:// with https://dweb.link/ipns/ prefix)

}

async function resolveDNSAndAddRule(domain) {
const contentPath = await client.resolve(`/ipns/${domain}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ this really needs a cache at some point (we can't send additional HTTP request to RPC api every time user opens new URL from already resolved domain)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this is an out of date file. I will push the updates shortly with the updated branch I've been working in 🤦. Luckily for me there was some things you caught that I wasn't doing in the new branch! so it was NOT a wasted effort :)

});
}

async function retryOnTabUpdate(tabId, info) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ i think we could make this smarter and redirect every public URL that returns true from IsIpfs.url test

For example, https://cloudflare-ipfs.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR does not get redirected to a local node because there is dynamic no rule for https://cloudflare-ipfs.com/ipfs/* – but it could with a few additional lines :)

We should detect when IsIpfs.url(info.url) returns true and then domain is different from the default public gateway (URL.host.endsWith('dweb.link')) and local one (URLhost.endsWith(localhost:8080')). In such case, we would add dynamic rule, just like we do for DNSLink. 👌

"action": {
"type": "redirect",
"redirect": {
"transform": { "scheme": "http", "host": "localhost", "port": "8080" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 given that port will be something that can be changed by the user, we will most likely end up adding these as dynamic rules during startup.

Comment on lines 34 to 49
- name: Restore .cache
uses: actions/cache@v3
id: cache
with:
path: ${{ github.workspace }}/.cache
key: ${{ runner.os }}-${{ hashFiles('package*json', 'yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('package*json', 'yarn.lock') }}
${{ runner.os }}-

- name: Restore node_modules
id: yarn-cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('package*json', 'yarn.lock') }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ please remove yarn.lock and this cache – npm ci uses package-lock.json and ignores yarn.lock anyway (which is good, we want to try using package-lock.json and remove yarn dependency)

@meandavejustice
Copy link
Collaborator Author

@lidel Thanks again for the review, I apologize for the branching mixup. I've got it working now correctly in this branch and addressed most of your comments. (I have two of them added to my todo list for the week). I'm going to go ahead and close this pr and open up a fresh one later on in the week. I need to add an updated list of features, and screenshots and clean up the git history.

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