ipfs-companion icon indicating copy to clipboard operation
ipfs-companion copied to clipboard

Brave: synchronize settings when backend is "Provided by Brave"

Open lidel opened this issue 2 years ago • 1 comments

Brave IPFS SOW 2023 has an item about exposing IPFS settings from brave://settings/ipfs to IPFS Companion extension. We want to be able to read them, and to change them programmatically.

I've described feature request details in https://github.com/brave/brave-browser/issues/31199, and the feature was implemented recently in https://github.com/brave/brave-core/pull/18901.

List of new APIs

New chrome.ipfs methods are available (brave-browser-beta-1.59.92 or later) ONLY to IPFS Companion Extension ID. These are privileged APIs that are NOT available to other extensions.

Reading IPFS Settings

  • chrome.ipfs.getSettings(callback) - returns a JSON with IPFS-related settings in Brave
    • chrome.ipfs.getSettings((a) => console.log(a)){"auto_redirect_to_configured_gateway":false,"gateway_auto_fallback_enabled":false,"gateway_url":"https://dweb.link","nft_gateway_url":"https://nftstorage.link","resolve_method":"local","storage_max":1}

Writing IPFS Settings

WRITING is limited to a subset of settings:

  • chrome.ipfs.setPublicGateway - sets current public gateway url
  • chrome.ipfs.setPublicNFTGateway - sets current public NFT gateway url (iiuc this is a privacy feature where images in Brave Wallet are not triggering fetch to local IPFS node, we probably should not touch this)
  • chrome.ipfs.setResolveMethod("local" | "gateway" | "ask" | "disabled") - sets IPFS resolution type ("local" here means Kubo node embedded in Brave, and "gateway" mean some other URL, it could be localhost from IPFS Desktop used by regular companion users).
  • chrome.ipfs.setAutoRedirectToConfiguredGatewayEnabled(true|false) - sets auto redirect setting
  • chrome.ipfs.setGatewayFallbackEnabled(true|false) - sets gateway fallback setting (fall back to public IPFS gateway if your Brave local IPFS node cannot be reached)

What IPFS Companion should do with them

We should synchronize gateway URLs and ensure redirect logic in brave and companion extension are not in conflict when "Provided by Brave" backend is used:

  1. If a user disables global redirects in Companion (2023-09-18_20-44 ) the automatic redirect MUST be also disabled in Brave (chrome.ipfs.setAutoRedirectToConfiguredGatewayEnabled(false))
    • Without this, a user may disable redirect in Companion, but still end up on local gateway due to redirect being enabled in Brave.
  2. If "Provided by Brave" backend IS used, companion MUST use Public Gateway URL from Brave:

    Unless we want to deal with bidirectional sync here, Companion Options should show read-only fields, like we already do for "Local Gateway" URL: 2023-09-18_20-40 Brave setting is the source of truth: 2023-09-18_20-13_1 We use Brave value for both fields (subdomain gateway).

  3. When "Provided by Brave" backend is NOT used in Companion, switch resolution method in Brave, to ensure user is not running two Kubo nodes on localhost:

    when Companion user switches backend from "Provided by Brave" to "External": 2023-09-18_20-09 we should switch Brave from chrome.ipfs.setResolveMethod("local") to chrome.ipfs.setResolveMethod("gateway") and disable all redirects (chrome.ipfs.setAutoRedirectToConfiguredGatewayEnabled(false)) in Brave, to ensure all IPFS responsibilities are delegated to in Companion (like it would in vanilla Google Chrome).

  4. (TBD) This needs research, but we may consider always disabling Brave redirect logic when IPFS Companion is enabled. Rationale is that Companion is more advanced and allows for opt-out from redirect per website, while Brave is global toggle, so will redirect even when companion user opted-out from redirecting specific website.

FAQ

  • How to detect Brave settings changes?
    • Checking once on extension start is enough.
    • When it comes to monitoring the Brave setting change, Companion can detect when a tab with brave://settings(.*) is open, and keep polling getSettings for updates every second, for as long the tab is open.
  • What if there is a bug in API (e.g. writing settings does not work)
    • Fill issue in https://github.com/brave/brave-browser/issues AND start thread in #shared-pl-brave on Slack

lidel avatar Sep 18 '23 18:09 lidel

@whizzzkid not super urgent, but this is something we should look into after MV3 work ships, so we have time in 2023 to report any bugs and Brave is able to fix them under 2023 SOW plan.

lidel avatar Sep 18 '23 18:09 lidel