Repository navigation
Add user-managed browser extensions #7841
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
Open
0xCUB3
wants to merge
51
commits into
manaflow-ai:main
Choose a base branch
from
0xCUB3:browser-web-extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
6e2b458
feat(browser): host web extensions via WKWebExtension (Bitwarden supp…
KyloJorgensen f6bd395
fix(browser): address review findings on web-extension support
KyloJorgensen 8aa9030
feat(settings): browser extension management in Settings > Browser
KyloJorgensen a18a5f4
feat(settings): import-based extension list instead of auto-discovery
KyloJorgensen 775753c
refactor(browser): drop Bitwarden auto-seed; settings are the only so…
KyloJorgensen 591415e
fix(browser): address review findings on extension management
KyloJorgensen e8b1dbb
Address browser extension review feedback
austinywang beb4209
Fix web extension unload and duplicate path state
austinywang d4d537e
Show duplicate web extension add feedback
austinywang bda4975
Fix browser extension panel lifecycle
austinywang 5afd758
Address web extension review comments
austinywang 223a38a
Order focused web extension window first
austinywang 5ba4f0d
Use localized format for duplicate extension alert
austinywang 87a0707
Fix web extension popout and window host wiring
austinywang f8849d5
Use localized format for manifest alert
austinywang 677411c
Allow WebKit native messaging bridge
austinywang 908140a
Forward web extension tab lifecycle
austinywang c3a9f1b
Hide imported extension paths from import menu
austinywang e685c71
Support extension tabs and action updates
austinywang cc43b81
Align web extension tab lifecycle with cmux focus
austinywang b6bda5b
Deduplicate Safari extension resource paths
austinywang c2bb853
Persist web extension navigation state
austinywang 7774770
Guard web extension imports until settings load
austinywang c134130
Fix web extension review findings
austinywang c515a14
Harden web extension loading gates
austinywang 622e5d1
Avoid redundant Safari extension reloads
austinywang 8ac7905
fix(browser): repair three compile errors on the extension branch
KyloJorgensen cb2171e
Route web extension tabs from dock panels
austinywang 39f66d8
Fix web extension window and toolbar updates
austinywang 1dd14fc
Fix web extension private windows and activation
austinywang 2d678da
test(browser): cover extension review regressions
austinywang 7c9c455
fix(browser): address extension review findings
austinywang 9c10d76
test(browser): cover remaining extension review regressions
austinywang 721d772
fix(browser): address remaining extension review findings
austinywang c5677dc
Fix browser extension review findings
austinywang 7c6bb51
test(browser): cover extension settings feedback
austinywang a9724a5
fix(browser): address remaining extension feedback
austinywang d56edb2
test(browser): cover clearing stale extension errors
austinywang 63fd83a
fix(browser): reconcile extension feedback state
austinywang 5508607
test(browser): cover extension lifecycle review regressions
austinywang 8f0f20f
fix(browser): address extension lifecycle review regressions
austinywang 4d3ad73
fix: hoist web-extension host creation out of StateObject autoclosure
austinywang fc8e336
test(browser): give each fake extension navigation a fresh configuration
austinywang 32a7650
Route extension commands (e.g. Bitwarden ⌘⇧L) while browser focus mod…
lawrence703 f75b432
ci: follow cmuxAuxiliaryWindowIdentifiers to its new file in the clos…
austinywang e352be5
fix: drop no-op await flagged by the Swift warning budget
austinywang 6063f15
fix(settings): don't flash 'no extensions added' before settings load
austinywang b5278d2
Complete user-managed browser web extensions
0xCUB3 b0fff2f
Address browser extension review feedback
0xCUB3 8d0d68d
Address remaining browser extension review feedback
0xCUB3 f2e19f1
Fix browser extension review regressions
0xCUB3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
Packages/macOS/CmuxSettings/Sources/CmuxSettings/Values/BrowserWebExtensionEntry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import Foundation | ||
|
|
||
| /// One web extension the user has configured for the built-in browser, stored | ||
| /// under `browser.webExtensions` in `cmux.json`. | ||
| /// | ||
| /// Extensions come from two places: Safari web extensions installed on this | ||
| /// Mac inside another app's bundle (discovered automatically), and unpacked | ||
| /// WebExtension directories the user added by hand. Only entries with | ||
| /// ``enabled`` set actually load; discovered-but-untouched extensions have no | ||
| /// entry at all. | ||
| /// | ||
| /// ```swift | ||
| /// BrowserWebExtensionEntry( | ||
| /// id: "com.bitwarden.desktop.safari", | ||
| /// kind: .safariAppExtension, | ||
| /// path: "/Applications/Bitwarden.app/Contents/PlugIns/safari.appex", | ||
| /// enabled: true | ||
| /// ) | ||
| /// ``` | ||
| public struct BrowserWebExtensionEntry: Codable, Sendable, Equatable, Hashable, Identifiable { | ||
| /// Where the extension's resources come from. | ||
| public enum Kind: String, Codable, Sendable { | ||
| /// A Safari web extension `.appex` bundled inside an installed app. | ||
| case safariAppExtension | ||
| /// A directory containing an unpacked WebExtension (`manifest.json` at | ||
| /// its root), Chrome/Firefox load-unpacked style. | ||
| case unpackedDirectory | ||
| } | ||
|
|
||
| /// Stable identity: the appex plug-in identifier for Safari extensions, or | ||
| /// the directory path for unpacked ones. | ||
| public var id: String | ||
| /// Where the extension's resources come from. | ||
| public var kind: Kind | ||
| /// Absolute path to the `.appex` bundle or unpacked directory. | ||
| public var path: String | ||
| /// Whether the extension loads into the browser. | ||
| public var enabled: Bool | ||
| /// Human-readable name captured when the extension was imported | ||
| /// (e.g. the containing app's name), shown in the settings list. | ||
| public var displayName: String? | ||
|
|
||
| /// - Parameters: | ||
| /// - id: Stable identity (appex plug-in identifier, or directory path). | ||
| /// - kind: Where the extension's resources come from. | ||
| /// - path: Absolute path to the `.appex` bundle or unpacked directory. | ||
| /// - enabled: Whether the extension loads into the browser. | ||
| /// - displayName: Human-readable name captured at import time. | ||
| public init(id: String, kind: Kind, path: String, enabled: Bool, displayName: String? = nil) { | ||
| self.id = id | ||
| self.kind = kind | ||
| self.path = path | ||
| self.enabled = enabled | ||
| self.displayName = displayName | ||
| } | ||
|
|
||
| /// Absolute, standardized path used to identify the effective extension | ||
| /// resource root for duplicate detection and reconciliation. | ||
| public var standardizedResourceRootPath: String { | ||
| Self.standardizedResourceRootPath(for: kind, path: path) | ||
| } | ||
|
|
||
| /// Returns a standardized filesystem path. | ||
| /// | ||
| /// - Parameter path: The path to normalize. | ||
| /// - Returns: The standardized file URL path. | ||
| public static func standardizedPath(_ path: String) -> String { | ||
| URL(fileURLWithPath: path) | ||
| .resolvingSymlinksInPath() | ||
| .standardizedFileURL | ||
| .path | ||
| } | ||
|
|
||
| /// Returns the effective resource root for a configured extension path. | ||
| /// | ||
| /// Safari app extensions load from `Contents/Resources` inside the `.appex` | ||
| /// bundle, so the bundle path and its resource directory compare equal. | ||
| /// | ||
| /// - Parameters: | ||
| /// - kind: The configured extension kind. | ||
| /// - path: The `.appex` bundle path or unpacked extension directory. | ||
| /// - Returns: The standardized effective resource-root path. | ||
| public static func standardizedResourceRootPath(for kind: Kind, path: String) -> String { | ||
| switch kind { | ||
| case .safariAppExtension: | ||
| return standardizedSafariAppExtensionResourceRootPath(path) | ||
| case .unpackedDirectory: | ||
| return standardizedPath(path) | ||
| } | ||
| } | ||
|
|
||
| /// Returns the resource root WebKit uses for a Safari app extension. | ||
| /// | ||
| /// - Parameter path: The `.appex` bundle path. | ||
| /// - Returns: `Contents/Resources` inside the bundle when `path` points at | ||
| /// an `.appex`, otherwise the standardized original path. | ||
| public static func standardizedSafariAppExtensionResourceRootPath(_ path: String) -> String { | ||
| let url = URL(fileURLWithPath: path) | ||
| .resolvingSymlinksInPath() | ||
| .standardizedFileURL | ||
| guard url.pathExtension == "appex" else { return url.path } | ||
| return url | ||
| .appendingPathComponent("Contents/Resources", isDirectory: true) | ||
| .resolvingSymlinksInPath() | ||
| .standardizedFileURL | ||
| .path | ||
| } | ||
| } | ||
|
|
||
| // MARK: - SettingCodable | ||
|
|
||
| /// Stored as a nested JSON object; a malformed entry is rejected (decodes to | ||
| /// `nil`) rather than partially applied, so bad config fails closed. | ||
| extension BrowserWebExtensionEntry: SettingCodable { | ||
| public static func decodeFromUserDefaults(_ raw: Any?) -> BrowserWebExtensionEntry? { | ||
| decodeFromJSON(raw) | ||
| } | ||
|
|
||
| public func encodeForUserDefaults() -> Any { | ||
| encodeForJSON() | ||
| } | ||
|
|
||
| public static func decodeFromJSON(_ raw: Any?) -> BrowserWebExtensionEntry? { | ||
| guard let object = raw as? [String: Any] else { return nil } | ||
| guard let data = try? JSONSerialization.data(withJSONObject: object) else { return nil } | ||
| return try? JSONDecoder().decode(BrowserWebExtensionEntry.self, from: data) | ||
| } | ||
|
|
||
| public func encodeForJSON() -> Any { | ||
| guard let data = try? JSONEncoder().encode(self), | ||
| let object = try? JSONSerialization.jsonObject(with: data) else { | ||
| return NSNull() | ||
| } | ||
| return object | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
Packages/macOS/CmuxSettings/Tests/CmuxSettingsTests/BrowserWebExtensionEntryTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import CmuxSettings | ||
|
|
||
| @Suite("Browser web extension resource identity") | ||
| struct BrowserWebExtensionEntryTests { | ||
| @Test | ||
| func unpackedDirectorySymlinkAliasSharesResourceIdentity() throws { | ||
| let root = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-web-extension-\(UUID().uuidString)", isDirectory: true) | ||
| let realDirectory = root.appendingPathComponent("real", isDirectory: true) | ||
| let aliasDirectory = root.appendingPathComponent("alias", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: realDirectory, withIntermediateDirectories: true) | ||
| try FileManager.default.createSymbolicLink(at: aliasDirectory, withDestinationURL: realDirectory) | ||
| defer { try? FileManager.default.removeItem(at: root) } | ||
|
|
||
| let realIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath( | ||
| for: .unpackedDirectory, | ||
| path: realDirectory.path | ||
| ) | ||
| let aliasIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath( | ||
| for: .unpackedDirectory, | ||
| path: aliasDirectory.path | ||
| ) | ||
|
|
||
| #expect(realIdentity == realDirectory.standardizedFileURL.path) | ||
| #expect(aliasIdentity == realIdentity) | ||
| } | ||
|
|
||
| @Test | ||
| func safariAppExtensionSymlinkAliasSharesResourcesIdentity() throws { | ||
| let root = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("cmux-safari-extension-\(UUID().uuidString)", isDirectory: true) | ||
| let realAppExtension = root.appendingPathComponent("Real.appex", isDirectory: true) | ||
| let resources = realAppExtension.appendingPathComponent("Contents/Resources", isDirectory: true) | ||
| let aliasAppExtension = root.appendingPathComponent("Alias.appex", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: resources, withIntermediateDirectories: true) | ||
| try FileManager.default.createSymbolicLink(at: aliasAppExtension, withDestinationURL: realAppExtension) | ||
| defer { try? FileManager.default.removeItem(at: root) } | ||
|
|
||
| let realIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath( | ||
| for: .safariAppExtension, | ||
| path: realAppExtension.path | ||
| ) | ||
| let aliasIdentity = BrowserWebExtensionEntry.standardizedResourceRootPath( | ||
| for: .safariAppExtension, | ||
| path: aliasAppExtension.path | ||
| ) | ||
|
|
||
| #expect(realIdentity == resources.standardizedFileURL.path) | ||
| #expect(aliasIdentity == realIdentity) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...muxSettingsUI/Sources/CmuxSettingsUI/Environment/SettingsDiscoveredBrowserExtension.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import Foundation | ||
|
|
||
| /// A Safari web extension found installed on this Mac, as reported by the | ||
| /// host through ``SettingsHostActions/discoverBrowserWebExtensions()``. | ||
| /// | ||
| /// This is display metadata only; the persisted setting is | ||
| /// `BrowserWebExtensionEntry` in the catalog. `id` matches the entry's `id` | ||
| /// (the appex plug-in identifier) so the Browser section can join the two. | ||
| public struct SettingsDiscoveredBrowserExtension: Sendable, Identifiable, Equatable { | ||
| /// The appex plug-in identifier (e.g. `com.bitwarden.desktop.safari`). | ||
| public let id: String | ||
| /// Human-readable name resolved from the extension bundle, if available. | ||
| public let displayName: String? | ||
| /// The extension's version string, if available. | ||
| public let version: String? | ||
| /// Absolute path to the `.appex` bundle. | ||
| public let path: String | ||
|
|
||
| /// - Parameters: | ||
| /// - id: The appex plug-in identifier. | ||
| /// - displayName: Human-readable name from the extension bundle. | ||
| /// - version: The extension's version string. | ||
| /// - path: Absolute path to the `.appex` bundle. | ||
| public init(id: String, displayName: String?, version: String?, path: String) { | ||
| self.id = id | ||
| self.displayName = displayName | ||
| self.version = version | ||
| self.path = path | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.