+
Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tsconfig.vitest-temp.json
/.cache
.output
.wxt
.idea
4 changes: 4 additions & 0 deletions packages/messaging/src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export function defineGenericMessanging<
removeRootListener = config.addRootListener(message => {
// Validate the message object
if (typeof message.type != 'string' || typeof message.timestamp !== 'number') {
// #77 When the message is invalid, we stop processing the message using return or throw an error (default)
if (config.breakError) {
return;
}
const err = Error(
`[messaging] Unknown message format, must include the 'type' & 'timestamp' fields, received: ${JSON.stringify(
message,
Expand Down
7 changes: 7 additions & 0 deletions packages/messaging/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export interface BaseMessagingConfig {
* @default console
*/
logger?: Logger;

/**
* Whether to break an error when an invalid message is received.
*
* @default undefined
*/
breakError?: boolean;
}

export interface NamespaceMessagingConfig extends BaseMessagingConfig {
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载