Skip to content

Commit

Permalink
fix: channel not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Mar 22, 2024
1 parent 7f7e1a3 commit f9180f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Extension/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class WebExtensionMessage<Message> extends EventTarget implements WebExte
const { e: event, t: target, o: origin } = payload
if (!shouldAcceptThisMessage(target)) return
let { d: data } = payload
if (encoded && this.serialization) data = await this.serialization.decode(data)
if (encoded && this.encoder) data = await this.encoder.decode(data)
if (this.enableLog) {
this.log(...this.logFormatter(this, event, data))
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export class WebExtensionMessage<Message> extends EventTarget implements WebExte
return this.#EventTarget
}

public serialization: Encoder | undefined
public encoder: Encoder | undefined
public logFormatter: (instance: this, key: string, data: unknown) => unknown[] = (instance, key, data) => {
return [
`%cReceive%c %c${String(key)}`,
Expand Down Expand Up @@ -218,7 +218,7 @@ export class WebExtensionMessage<Message> extends EventTarget implements WebExte
}
if (target & MessageTarget.LocalOnly) return
postMessage({
d: this.serialization ? await this.serialization.encode(data) : data,
d: this.encoder ? await this.encoder.encode(data) : data,
s: this.#domain,
e: eventName,
t: {
Expand Down Expand Up @@ -472,6 +472,7 @@ function pageOnBoarding(connect: () => Runtime.Port) {
postMessage = postMessageInner.bind(null, pageLocal)
self.addEventListener('unload', () => {
postMessage(FARWELL)
pageLocal.broadcastChannel?.removeEventListener('message', pageMessageListener)
pageLocal.broadcastChannel?.close()
})
}
Expand Down Expand Up @@ -500,6 +501,7 @@ function pageOnBoarding(connect: () => Runtime.Port) {
pageLocal.uuid ??= uuid
if (getEnvironment() & Environment.ExtensionProtocol) {
pageLocal.broadcastChannel ??= new BroadcastChannel(uuid)
pageLocal.broadcastChannel.addEventListener('message', pageMessageListener)
}
resolve(port)
})
Expand Down

0 comments on commit f9180f3

Please sign in to comment.