diff --git a/source/src/background.ts b/source/src/background.ts index 373bf8e..ef7338a 100644 --- a/source/src/background.ts +++ b/source/src/background.ts @@ -4,6 +4,7 @@ import {Msg, Page, PluginEvent} from "@/core/types"; import * as UA from "universal-analytics" import {v4} from "uuid" import {devtools_page} from "./manifest.json" +import {FrameDetails} from "@/devtools/data"; // 统计服务 const userID = localStorage.getItem("userID") || v4() @@ -45,10 +46,22 @@ class PortMan { return this.content.find(el => el.sender?.frameId !== undefined && el.sender.frameId === this.currentUseContentFrameID) || null; } + _updateFrames() { + let data: FrameDetails[] = this.content.map(item => { + return { + url: item.sender?.url || "", + frameID: item.sender?.frameId || 0, + } + }) + let event = new PluginEvent(Page.Background, Page.Devtools, Msg.UpdateFrames, data) + this.sendDevtoolMsg(event) + } + dealConnect(port: chrome.runtime.Port) { switch (port.name) { case Page.Content: { this.content.push(port); + this._updateFrames(); this.onPortConnect(port, (data: PluginEvent) => { if (data.target === Page.Devtools) { @@ -62,12 +75,14 @@ class PortMan { && el.sender?.frameId === disPort.sender?.frameId ); this.content.splice(index, 1); + this._updateFrames(); this.checkValid(); }) break; } case Page.Devtools: { this.devtools = port; + this._updateFrames(); // 当devtools链接后,主动派发frames数据 this.onPortConnect(port, (data: PluginEvent) => { // 从devtools过来的消息统一派发到Content中 diff --git a/source/src/core/types.ts b/source/src/core/types.ts index a8eb5cd..a631a6c 100644 --- a/source/src/core/types.ts +++ b/source/src/core/types.ts @@ -14,6 +14,7 @@ export enum Msg { MemoryInfo = "memory-info",// TabsInfo = "tabs_info", // 当前页面信息 GetTabID = "GetTabID", // 获取页面ID + UpdateFrames = "UpdateFrames", // 更新页面的frame GetObjectItemData = "GetObjectItemData", SetProperty = "set-property", // 设置node属性 UpdateProperty = "update-property", // 更新属性 diff --git a/source/src/devtools/data.ts b/source/src/devtools/data.ts index 6535089..72771aa 100644 --- a/source/src/devtools/data.ts +++ b/source/src/devtools/data.ts @@ -41,6 +41,11 @@ export interface ObjectItemRequestData { data: Property[]; } +export interface FrameDetails { + frameID: number; + url: string; +} + export class EngineData extends Info { public engineType: string = ""; public engineUUID: string = ""; diff --git a/source/src/devtools/ui/index.vue b/source/src/devtools/ui/index.vue index bde0ad8..a648f75 100644 --- a/source/src/devtools/ui/index.vue +++ b/source/src/devtools/ui/index.vue @@ -1,5 +1,12 @@