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

meet adr 006 #134

Merged
merged 8 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/witty-bags-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@repo/context': minor
'chrome-extension': minor
---

Update packages
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ lerna-debug.log*
# pack outputs
penumbra-zone-*.tgz
packages/*/package

apps/extension/chromium-profile

4 changes: 0 additions & 4 deletions apps/extension/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@connectrpc/connect-web": "1.4.0",
"@penumbra-labs/registry": "11.0.0",
"@penumbra-zone/bech32m": "^6.1.1",
"@penumbra-zone/client": "^16.0.0",
"@penumbra-zone/client": "^17.0.0",
"@penumbra-zone/crypto-web": "^20.0.0",
"@penumbra-zone/getters": "^14.0.0",
"@penumbra-zone/keys": "^4.2.1",
Expand All @@ -30,7 +30,7 @@
"@penumbra-zone/query": "^25.0.0",
"@penumbra-zone/services": "^28.0.0",
"@penumbra-zone/storage": "^24.0.0",
"@penumbra-zone/transport-chrome": "^8.0.0",
"@penumbra-zone/transport-chrome": "^8.0.1",
"@penumbra-zone/transport-dom": "^7.5.0",
"@penumbra-zone/types": "^19.0.0",
"@penumbra-zone/wasm": "^24.0.0",
Expand Down
6 changes: 1 addition & 5 deletions apps/extension/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
"content_scripts": [
{
"matches": ["https://*/*"],
"js": [
"injected-connection-port.js",
"injected-disconnect-listener.js",
"injected-request-listener.js"
],
"js": ["injected-connection-port.js", "injected-request-listener.js"],
"run_at": "document_start"
},
{
Expand Down
65 changes: 29 additions & 36 deletions apps/extension/src/content-scripts/injected-connection-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,36 @@ import { CRSessionClient } from '@penumbra-zone/transport-chrome/session-client'
import { PraxConnection } from '../message/prax';
import { PraxMessage } from './message-event';

// this script will init the page session upon instruction from an extension
// worker. init does not arrive in direct response to an emitted message, it is
// independent.

// handler to listen for init command for this document
const initOnce = (
req: unknown,
// content script message handlers are activated only by another
// script in the same extension using chrome.tabs.sendMessage
sender: chrome.runtime.MessageSender,
// this handler will only ever send an empty response
respond: (no?: never) => void,
) => {
if (req !== PraxConnection.Init) {
// boolean return in handlers signals intent to respond
const end = { [PRAX]: PraxConnection.End } satisfies PraxMessage<PraxConnection.End>;

let port: MessagePort | undefined;

chrome.runtime.onMessage.addListener(
(req: unknown, sender: chrome.runtime.MessageSender, respond: (no?: never) => void) => {
if (typeof req === 'string' && req in PraxConnection) {
if (sender.id !== PRAX) {
throw new Error(`Unexpected sender ${sender.id}`);
}
switch (req as PraxConnection) {
case PraxConnection.Init: {
port ??= CRSessionClient.init(PRAX);
window.postMessage({ [PRAX]: port } satisfies PraxMessage<MessagePort>, '/', [port]);
respond();
return true;
}
case PraxConnection.End: {
port = undefined;
window.postMessage(end, '/');
respond();
return true;
}
default:
return false;
}
}
return false;
}

chrome.runtime.onMessage.removeListener(initOnce);

if (sender.id !== PRAX) {
throw new Error(`Unexpected sender ${sender.id}`);
}

// create session, post port to window where the injected global can catch it.
const port = CRSessionClient.init(PRAX);
window.postMessage({ [PRAX]: port } satisfies PraxMessage<MessagePort>, '/', [port]);

// handler is done
respond();

// boolean return in handlers signals intent to respond
return true;
};

// attach handler
chrome.runtime.onMessage.addListener(initOnce);
},
);

// announce
void chrome.runtime.sendMessage(PraxConnection.Init);
10 changes: 0 additions & 10 deletions apps/extension/src/content-scripts/injected-disconnect-listener.ts

This file was deleted.

Loading