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

don't retain port in content scripts #285

Open
wants to merge 2 commits into
base: connection-lifecycle-branch
Choose a base branch
from

Conversation

turbocrime
Copy link
Collaborator

Content scripts no longer retain a MessagePort in violation of object transfer rules.

Related to penumbra-zone/web#2018

Copy link
Collaborator Author

@turbocrime turbocrime left a comment

Choose a reason for hiding this comment

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

commentary. possibly should minimize extra changes

apps/extension/public/manifest.json Show resolved Hide resolved
Comment on lines +22 to +23
import { createPenumbraStateEvent } from '@penumbra-zone/client/event';
import type { PenumbraProvider } from '@penumbra-zone/client/provider';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not strictly necessary, but due to poor webpack tree-shaking, importing from the root package apparently caused the generated script to be very large.

a more specific import significantly reduces the size of the content script.

disconnect: () => this.postDisconnectRequest(),
isConnected: () => Boolean(this.port && this.presentState === PenumbraState.Connected),
isConnected: () => this.presentState === PenumbraState.Connected,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i would like to do some more investigation to identify possibly unknown problems with these changes to state transitions

Comment on lines +98 to +102
private postDisconnectRequest() {
const attempt = this.listenEndMessage();
window.postMessage(disconnectMessage, '/', []);
return attempt;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pulled this out into its own method to match the structure of the connect request logic

Comment on lines +105 to +107
if (this.presentState !== PenumbraState.Connected) {
this.setPending();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this change needs some closer inspection too

@turbocrime turbocrime marked this pull request as draft February 4, 2025 01:32
@TalDerei TalDerei marked this pull request as ready for review February 4, 2025 19:53
Copy link
Contributor

@TalDerei TalDerei left a comment

Choose a reason for hiding this comment

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

looks like the changeset primarily consolidated content scripts, removed global port object, and better message handling.

Comment on lines +98 to +99
window.addEventListener('message', praxDocumentListener);
chrome.runtime.onMessage.addListener(praxExtensionListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add code comments to the two event listeners, praxDocumentListener and praxExtensionListener?

@TalDerei TalDerei changed the base branch from main to connection-lifecycle-branch February 4, 2025 23:07
@TalDerei TalDerei self-requested a review February 4, 2025 23:08
Copy link
Contributor

@TalDerei TalDerei left a comment

Choose a reason for hiding this comment

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

changed base branch to connection-lifecycle-refactor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants