Skip to content

Commit

Permalink
🐛 修复firefox环境下GM_addElement的问题 #291
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 8, 2024
1 parent faeb30c commit 013a4f6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/app/message/content.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LoggerCore from "../logger/core";
import { Channel } from "./channel";
import {
ChannelManager,
Expand Down Expand Up @@ -107,15 +108,6 @@ export default class MessageContent

nativeSend(data: any): void {
let detail = data;
if (typeof cloneInto !== "undefined") {
try {
// eslint-disable-next-line no-undef
detail = cloneInto(detail, document.defaultView);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
}
}

// 特殊处理relatedTarget
if (detail.data && typeof detail.data.relatedTarget === "object") {
Expand All @@ -135,6 +127,18 @@ export default class MessageContent
document.dispatchEvent(ev);
}

if (typeof cloneInto !== "undefined") {
try {
LoggerCore.getLogger().info("nativeSend");
// eslint-disable-next-line no-undef
detail = cloneInto(detail, document.defaultView);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
LoggerCore.getLogger().info("error data");
}
}

const ev = new CustomEvent((this.isContent ? "fd" : "ct") + this.eventId, {
detail,
});
Expand Down

0 comments on commit 013a4f6

Please sign in to comment.