-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add Edge/Chromium browser extension support #138
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
Merged
iinuwa
merged 5 commits into
linux-credentials:main
from
phelix001:feat/edge-chromium-webext
Apr 22, 2026
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f08c72f
feat: add Edge/Chromium web extension port
phelix001 c40bce0
refactor: merge Firefox and Chromium add-ons into unified folder
phelix001 58d581e
docs: update READMEs for unified browser extension
phelix001 6ba8ab7
webext: address review feedback on manifest and meson build
phelix001 93d7eca
webext: use service_worker background in Firefox manifest
phelix001 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /** | ||
| * Background service worker for Edge/Chromium. | ||
| * Bridges content script messages to the native messaging host. | ||
| */ | ||
|
|
||
| let contentPort; | ||
| let nativePort; | ||
|
|
||
| function arrayBufferToBase64url(buffer) { | ||
| const bytes = new Uint8Array(buffer); | ||
| let binary = ''; | ||
| for (let i = 0; i < bytes.length; i++) { | ||
| binary += String.fromCharCode(bytes[i]); | ||
| } | ||
| return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); | ||
| } | ||
|
|
||
| function base64urlToBytes(str) { | ||
| if (!str) return null; | ||
| const padded = str.replace(/-/g, '+').replace(/_/g, '/'); | ||
| const binary = atob(padded); | ||
| const bytes = new Uint8Array(binary.length); | ||
| for (let i = 0; i < binary.length; i++) { | ||
| bytes[i] = binary.charCodeAt(i); | ||
| } | ||
| return bytes; | ||
| } | ||
|
|
||
| function connected(port) { | ||
| console.log('[credentialsd] received connection from content script'); | ||
| contentPort = port; | ||
|
|
||
| // Connect to native messaging host | ||
| nativePort = chrome.runtime.connectNative('xyz.iinuwa.credentialsd_helper'); | ||
| if (chrome.runtime.lastError) { | ||
| console.error('[credentialsd] native connect error:', chrome.runtime.lastError.message); | ||
| return; | ||
| } | ||
| console.log('[credentialsd] connected to native app'); | ||
|
|
||
| contentPort.onMessage.addListener(rcvFromContent); | ||
| nativePort.onMessage.addListener(rcvFromNative); | ||
|
|
||
| nativePort.onDisconnect.addListener(() => { | ||
| if (chrome.runtime.lastError) { | ||
| console.error('[credentialsd] native port disconnected:', chrome.runtime.lastError.message); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function rcvFromContent(msg) { | ||
| const { requestId, cmd, options } = msg; | ||
| const origin = contentPort.sender.origin; | ||
| const topOrigin = new URL(contentPort.sender.tab.url).origin; | ||
|
|
||
| if (options) { | ||
| const serializedOptions = serializeRequest(options); | ||
| console.debug('[credentialsd] forwarding', cmd, 'to native app'); | ||
| nativePort.postMessage({ requestId, cmd, options: serializedOptions, origin, topOrigin }); | ||
| } else { | ||
| console.debug('[credentialsd] forwarding', cmd, '(no options) to native app'); | ||
| nativePort.postMessage({ requestId, cmd, origin, topOrigin }); | ||
| } | ||
| } | ||
|
|
||
| function rcvFromNative(msg) { | ||
| console.log('[credentialsd] received from native, forwarding to content'); | ||
| contentPort.postMessage(msg); | ||
| } | ||
|
|
||
| function serializeBytes(buffer) { | ||
| if (buffer && buffer.__b64url__) { | ||
| // Already base64url-encoded by the MAIN world script | ||
| return buffer.__b64url__; | ||
| } | ||
| if (buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer)) { | ||
| return arrayBufferToBase64url(buffer); | ||
| } | ||
| if (typeof buffer === 'string') { | ||
| return buffer; | ||
| } | ||
| return buffer; | ||
| } | ||
|
|
||
| function serializeRequest(options) { | ||
| const clone = JSON.parse(JSON.stringify(options)); | ||
|
|
||
| // The MAIN world script serialized ArrayBuffers as { __b64url__: "..." } | ||
| // Unwrap these for the native host | ||
| function unwrapB64url(obj) { | ||
| if (obj === null || obj === undefined) return obj; | ||
| if (typeof obj !== 'object') return obj; | ||
| if (obj.__b64url__) return obj.__b64url__; | ||
| if (Array.isArray(obj)) return obj.map(unwrapB64url); | ||
| const result = {}; | ||
| for (const key of Object.keys(obj)) { | ||
| result[key] = unwrapB64url(obj[key]); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| return unwrapB64url(clone); | ||
| } | ||
|
|
||
| // Listen for connections from content script | ||
| console.log('[credentialsd] background service worker starting (Edge/Chromium)'); | ||
| chrome.runtime.onConnect.addListener(connected); | ||
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,33 @@ | ||
| /** | ||
| * Content script running in ISOLATED world. | ||
| * Bridges window.postMessage from the MAIN world content script | ||
| * to the background service worker via chrome.runtime.connect. | ||
| */ | ||
|
|
||
| const port = chrome.runtime.connect({ name: 'credentialsd-helper' }); | ||
|
|
||
| // Forward responses from background back to page context | ||
| port.onMessage.addListener((msg) => { | ||
| const { requestId, data, error } = msg; | ||
| window.postMessage({ | ||
| type: 'credentialsd-response', | ||
| requestId, | ||
| data, | ||
| error, | ||
| }, '*'); | ||
| }); | ||
|
|
||
| port.onDisconnect.addListener(() => { | ||
| console.warn('[credentialsd] background port disconnected'); | ||
| }); | ||
|
|
||
| // Listen for requests from the MAIN world content script | ||
| window.addEventListener('message', (event) => { | ||
| if (event.source !== window) return; | ||
| if (event.data?.type !== 'credentialsd-request') return; | ||
|
|
||
| const { requestId, cmd, options } = event.data; | ||
| port.postMessage({ requestId, cmd, options }); | ||
| }); | ||
|
|
||
| console.log('[credentialsd] content bridge active (Edge/Chromium)'); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is built into Chromium as Uint8Array.from/toBase64; can we use those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done — switched to native
Uint8Array.toBase64()/fromBase64()with{alphabet: "base64url", omitPadding: true}throughout. The manual btoa/atob helpers are removed entirely.