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: reload failed IPFS tabs when API becomes available #1092

Merged
merged 19 commits into from
Sep 26, 2022

Conversation

whizzzkid
Copy link
Contributor

@whizzzkid whizzzkid commented Aug 24, 2022

Closes #1010

In this PR:

  • I added support for reloading failed tabs when API is available again, by:
    • By statically checking for failed tabs which belongs to local gateway instead of tracking all URLs.
    • This reduces the complexity for tracking failed websites in content_scripts.
    • More details on the implementation can be found in the relevant reloader.
  • I am also introducing a plugin mechanism that can register different reloader classes, this provides decent segregation of validation logic and also allows us to have reusable code for reloading.
  • Added relevant unit tests for 100% coverage.
  • Also updated the yarn.lock file and added a matching .editorconfig to configure IDEs.

Screencast:

output.mp4

@whizzzkid whizzzkid requested a review from lidel as a code owner August 24, 2022 06:30
@welcome

This comment was marked as resolved.

@whizzzkid whizzzkid changed the title Modifying how to check for bad state [Issue-1010] Reload failed IPFS tabs when API becomes available Aug 24, 2022
Copy link
Contributor Author

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

Adding explainer comments

insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to remove ambiguity from IDEs

// those pages.
// - The benefit we get from this approach is the static nature of just observing the tabs in their current state.
// which reduces the overhead of injecting content scripts to track urls that were loaded after the connection
// was offline, it may also need extra permissions to inject code on error pages.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this logic validates offline pages belonging to IPFS node.

@@ -141,7 +141,7 @@
"webextension-polyfill": "0.7.0"
},
"engines": {
"node": ">=14.15.0",
"node": ">=14.15.0 <17",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for some reason latest LTS (18) fails to build this. I did not investigate, but added check to prevent this.

Copy link
Member

Choose a reason for hiding this comment

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

+1. a lot of our packages and their dependencies are out of date, and there have been a lot of changes made w.r.t. esm support, so we've been in a tough spot. However, you can see our support goals at https://github.com/ipfs/ipfs-gui/tree/SgtPooki-version-support-definition#nodejs (We can link to main branch when ipfs/ipfs-gui#97 gets merged)

add-on/src/lib/ipfs-client/index.js Outdated Show resolved Hide resolved
add-on/src/lib/ipfs-client/index.js Outdated Show resolved Hide resolved
add-on/src/lib/ipfs-client/index.js Outdated Show resolved Hide resolved
add-on/src/lib/ipfs-client/index.js Outdated Show resolved Hide resolved
add-on/src/lib/ipfs-client/reloaders/index.js Outdated Show resolved Hide resolved
add-on/src/lib/ipfs-client/reloaders/index.js Outdated Show resolved Hide resolved
@@ -141,7 +141,7 @@
"webextension-polyfill": "0.7.0"
},
"engines": {
"node": ">=14.15.0",
"node": ">=14.15.0 <17",
Copy link
Member

Choose a reason for hiding this comment

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

+1. a lot of our packages and their dependencies are out of date, and there have been a lot of changes made w.r.t. esm support, so we've been in a tough spot. However, you can see our support goals at https://github.com/ipfs/ipfs-gui/tree/SgtPooki-version-support-definition#nodejs (We can link to main branch when ipfs/ipfs-gui#97 gets merged)

@whizzzkid whizzzkid requested review from SgtPooki and removed request for lidel August 30, 2022 05:08
@whizzzkid
Copy link
Contributor Author

@SgtPooki looks like the builds are failing on windows-latest I created a PR to address that: #1094 can you please try that?

@lidel lidel self-requested a review September 1, 2022 15:03
@lidel lidel changed the title [Issue-1010] Reload failed IPFS tabs when API becomes available fix: reload failed IPFS tabs when API becomes available Sep 8, 2022
@lidel lidel changed the title fix: reload failed IPFS tabs when API becomes available feat: reload failed IPFS tabs when API becomes available Sep 8, 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 @whizzzkid, before we land this, do you mind

  • rebasing this to include fix from fix(ci): windows build #1094 (which already landed in main branch)
  • improving URL check to also work for subdomain gateways (details inline)
  • (optional) perhaps we could avoid title matching by leveraging onErrorOccurred? (details inline – not a blocker, could be descoped and filled as an issue for future improvement, lmk if you prefer that)

* was offline, it may also need extra permissions to inject code on error pages.
*/
return url.startsWith(this.customGatewayUrl) &&
(url.includes(title) || title.toLowerCase() === 'problem loading page')
Copy link
Member

Choose a reason for hiding this comment

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

two nits:

  • startsWith does not cover subdomain gateways
  • browser vendors may change the title (in Firefox it will be different for non-english locale)
    • (loose idea, not sure how feasible) potential improvement would be to leverage onErrorOccurred from src/lib/ipfs-request.js and inside of it, add isRecoverableViaOnlineApi which would save failed requests to local gateway in a cache similar to errorInFlight. Then, you could check if url is present in that cache, removing the need for matching titles. More complicated, but future-proof :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @lidel

  • the check should be isIPFS.url || isIPFS.subdomain and not isIPFS.url && isIPFS.subdomain added that.
  • I'll create a separate issue for that, It was on my mind but this PR is large as it is, I'll work on that issue separately.

Copy link
Member

Choose a reason for hiding this comment

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

@whizzzkid mind linking to the created issue or creating it and commenting here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, #1097

Can you please assign this to me @SgtPooki/@lidel

Comment on lines +10 to +14
validation ({ url }) {
const bundled = !url.startsWith('http') && url.includes('/webui/index.html#/')
const ipns = url.includes('/webui.ipfs.io/#/')
return bundled || ipns
}
Copy link
Member

@lidel lidel Sep 8, 2022

Choose a reason for hiding this comment

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

nit: built-in webui at http://127.0.0.1:5001/webui/ returns redirect to http://127.0.0.1:5001/ipfs/{hardcoded-cid} (hardcoded-cid here)

It seems to be missing here, is it reloaded by some other means? (if not, we may want to add it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This functionality was brought in from: https://github.com/ipfs/ipfs-companion/blob/main/add-on/src/lib/ipfs-client/index.js#L64-L68

But now that I think more about it, this will be handled in the localGatewayReloader check as isIPFS.url || isIPFS.subdomain returns true for http://127.0.0.1:5001/ipfs/bafybeibozpulxtpv5nhfa2ue3dcjx23ndh3gwr5vwllk7ptoyfwnfjjr4q hardcoded cid.

@whizzzkid
Copy link
Contributor Author

whizzzkid commented Sep 11, 2022

@lidel @SgtPooki this is ready for re-review:

Build is now 🟢 https://github.com/whizzzkid/ipfs-companion/actions/runs/3033417199

❤️

@whizzzkid whizzzkid requested review from lidel and SgtPooki and removed request for SgtPooki and lidel September 11, 2022 22:05
@BigLep
Copy link
Contributor

BigLep commented Sep 19, 2022

@SgtPooki : is there any other feedback, or can this be merged?

@SgtPooki
Copy link
Member

GUI triage: Lidel is going to give a look at this. We need to fix companion build pipeline before merging this

@SgtPooki SgtPooki requested a review from lidel September 19, 2022 17:03
@whizzzkid
Copy link
Contributor Author

@SgtPooki are the build pipelines broken again? I fixed the companion pipeline in #1094

* was offline, it may also need extra permissions to inject code on error pages.
*/
return url.startsWith(this.customGatewayUrl) &&
(url.includes(title) || title.toLowerCase() === 'problem loading page')
Copy link
Member

Choose a reason for hiding this comment

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

@whizzzkid mind linking to the created issue or creating it and commenting here?

@SgtPooki
Copy link
Member

SgtPooki commented Sep 24, 2022

@SgtPooki are the build pipelines broken again? I fixed the companion pipeline in #1094

Sorry we missed that =) Gave my approval but I've got very little experience in this repo so I'm leaving the PR open for @lidel to handle when he gets to it. I'd ping him Monday if it's not merged by then

@SgtPooki SgtPooki added status/ready Ready to be worked need/maintainer-input Needs input from the current maintainer(s) labels Sep 24, 2022
@SgtPooki
Copy link
Member

GUI triage: Lidel is going to give a look at this. We need to fix companion build pipeline before merging this

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 @whizzzkid and @SgtPooki

LGTM, there are unrelated issues caused by old dependencies (will fill separate issues if I have no time to fix them myself), but the functionality of this PR is good!

I'm merging it to unblock follow-up work from #1097

Comment on lines +78 to +82
it('should handle internal tab reloading', function () {
const tabs = [{
url: 'http://127.0.0.1:8080/ipfs/cid/wiki1',
id: 1
}, {
Copy link
Member

Choose a reason for hiding this comment

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

@whizzzkid in browser context we also need to test subdomain gateway at localhost (one for .ipns.localhost:8080 and one for .ipfs.localhost:8080) That is what is used by users by default these days.

Not blocking this PR on this, but added it as additional task to #1097 :)

@lidel lidel merged commit 8a33b6c into ipfs:main Sep 26, 2022
@whizzzkid whizzzkid deleted the feature/1010-reload-failed-IPFS-tabs branch September 27, 2022 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/maintainer-input Needs input from the current maintainer(s) status/ready Ready to be worked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reload failed IPFS tabs when API becomes available
4 participants