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

Suggestion: use typescript and shared message type definitions. #14

Open
edeykholt opened this issue Jun 20, 2024 · 0 comments
Open

Suggestion: use typescript and shared message type definitions. #14

edeykholt opened this issue Jun 20, 2024 · 0 comments

Comments

@edeykholt
Copy link

edeykholt commented Jun 20, 2024

Typescript will avoid some errors.

Suggest somewhere the message type definitions for those between a webpage and an ContentScript injected by an extension are defined in a separate .ts. Something like the following example:

// Message types from page to content script
const PAGE_EVENT_TYPE = Object.freeze({
SELECT_IDENTIFIER: "select-identifier",
SELECT_CREDENTIAL: "select-credential",
SELECT_ID_CRED: "select-aid-or-credential",
SELECT_AUTO_SIGNIN: "select-auto-signin",
NONE: "none",
VENDOR_INFO: "vendor-info",
FETCH_RESOURCE: "fetch-resource",
AUTO_SIGNIN_SIG: "auto-signin-sig",
SIGNIFY_EXTENSION: "signify-extension"
})

// Message types from content script to page
const PAGE_POST_TYPE = Object.freeze({
SIGNIFY_EXT: "signify-extension",
SELECT_AUTO_SIGNIN: "select-auto-signin",
SIGNIFY_SIGNATURE: "signify-signature"
})

// interfaces for the messages posted to the web page
interface ICsPageMsg {
type: any
version: string
}

interface ICsPageSignifyExtensionMsg extends ICsPageMsg {
type: typeof PAGE_POST_TYPE.SIGNIFY_EXT;
version: "0.0.1"
data: {
extensionId: string;
};
}
...
With these, a browser extension developer then can import these definition and use the ones it needs.
A webpage developer can import and use the ones it needs.

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

No branches or pull requests

1 participant