From 23240536b7d68589eb7b2d2ef900fdbf061d2774 Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Tue, 13 Sep 2022 16:11:48 +0200 Subject: [PATCH] feat(tracker): wip: replace-rule with no new messages --- backend/pkg/messages/filters.go | 2 +- backend/pkg/messages/messages.go | 40 --------------- backend/pkg/messages/read-message.go | 21 -------- ee/connectors/msgcodec/messages.py | 10 ---- ee/connectors/msgcodec/msgcodec.py | 8 --- .../messages/JSONRawMessageReader.ts | 7 --- .../messages/RawMessageReader.ts | 14 ------ .../MessageDistributor/messages/message.ts | 3 -- .../player/MessageDistributor/messages/raw.ts | 10 +--- .../messages/tracker-legacy.ts | 1 - .../MessageDistributor/messages/tracker.ts | 20 +------- mobs/messages.rb | 31 ++++++------ tracker/tracker/src/common/messages.gen.ts | 11 +--- tracker/tracker/src/main/app/messages.gen.ts | 15 ------ tracker/tracker/src/main/modules/cssrules.ts | 50 +++++++------------ .../src/webworker/MessageEncoder.gen.ts | 4 -- 16 files changed, 38 insertions(+), 209 deletions(-) diff --git a/backend/pkg/messages/filters.go b/backend/pkg/messages/filters.go index 9f647586e..e79d1d987 100644 --- a/backend/pkg/messages/filters.go +++ b/backend/pkg/messages/filters.go @@ -2,7 +2,7 @@ package messages func IsReplayerType(id int) bool { - return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 79 == id || 83 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id + return 0 == id || 4 == id || 5 == id || 6 == id || 7 == id || 8 == id || 9 == id || 10 == id || 11 == id || 12 == id || 13 == id || 14 == id || 15 == id || 16 == id || 18 == id || 19 == id || 20 == id || 22 == id || 37 == id || 38 == id || 39 == id || 40 == id || 41 == id || 44 == id || 45 == id || 46 == id || 47 == id || 48 == id || 49 == id || 54 == id || 55 == id || 59 == id || 60 == id || 61 == id || 67 == id || 69 == id || 70 == id || 71 == id || 72 == id || 73 == id || 74 == id || 75 == id || 76 == id || 77 == id || 79 == id || 90 == id || 93 == id || 96 == id || 100 == id || 102 == id || 103 == id || 105 == id } func IsIOSType(id int) bool { diff --git a/backend/pkg/messages/messages.go b/backend/pkg/messages/messages.go index fdd696609..8cdb95722 100644 --- a/backend/pkg/messages/messages.go +++ b/backend/pkg/messages/messages.go @@ -158,8 +158,6 @@ const ( MsgZustand = 79 - MsgReplaceVCSS = 83 - MsgIOSBatchMeta = 107 MsgIOSSessionStart = 90 @@ -3076,44 +3074,6 @@ func (msg *Zustand) TypeID() int { return 79 } -type ReplaceVCSS struct { - message - ID uint64 - Styles string - SheetID uint64 - BaseURL string -} - -func (msg *ReplaceVCSS) Encode() []byte { - buf := make([]byte, 41+len(msg.Styles)+len(msg.BaseURL)) - buf[0] = 83 - p := 1 - p = WriteUint(msg.ID, buf, p) - p = WriteString(msg.Styles, buf, p) - p = WriteUint(msg.SheetID, buf, p) - p = WriteString(msg.BaseURL, buf, p) - return buf[:p] -} - -func (msg *ReplaceVCSS) EncodeWithIndex() []byte { - encoded := msg.Encode() - if IsIOSType(msg.TypeID()) { - return encoded - } - data := make([]byte, len(encoded)+8) - copy(data[8:], encoded[:]) - binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index) - return data -} - -func (msg *ReplaceVCSS) Decode() Message { - return msg -} - -func (msg *ReplaceVCSS) TypeID() int { - return 83 -} - type IOSBatchMeta struct { message Timestamp uint64 diff --git a/backend/pkg/messages/read-message.go b/backend/pkg/messages/read-message.go index 8dc991c86..1b0f579af 100644 --- a/backend/pkg/messages/read-message.go +++ b/backend/pkg/messages/read-message.go @@ -1318,24 +1318,6 @@ func DecodeZustand(reader io.Reader) (Message, error) { return msg, err } -func DecodeReplaceVCSS(reader io.Reader) (Message, error) { - var err error = nil - msg := &ReplaceVCSS{} - if msg.ID, err = ReadUint(reader); err != nil { - return nil, err - } - if msg.Styles, err = ReadString(reader); err != nil { - return nil, err - } - if msg.SheetID, err = ReadUint(reader); err != nil { - return nil, err - } - if msg.BaseURL, err = ReadString(reader); err != nil { - return nil, err - } - return msg, err -} - func DecodeIOSBatchMeta(reader io.Reader) (Message, error) { var err error = nil msg := &IOSBatchMeta{} @@ -1972,9 +1954,6 @@ func ReadMessage(t uint64, reader io.Reader) (Message, error) { case 79: return DecodeZustand(reader) - case 83: - return DecodeReplaceVCSS(reader) - case 107: return DecodeIOSBatchMeta(reader) diff --git a/ee/connectors/msgcodec/messages.py b/ee/connectors/msgcodec/messages.py index d4bdf70d8..e1fe393a4 100644 --- a/ee/connectors/msgcodec/messages.py +++ b/ee/connectors/msgcodec/messages.py @@ -752,16 +752,6 @@ class Zustand(Message): self.state = state -class ReplaceVCSS(Message): - __id__ = 83 - - def __init__(self, id, styles, sheet_id, base_url): - self.id = id - self.styles = styles - self.sheet_id = sheet_id - self.base_url = base_url - - class IOSBatchMeta(Message): __id__ = 107 diff --git a/ee/connectors/msgcodec/msgcodec.py b/ee/connectors/msgcodec/msgcodec.py index 910f40637..d53c3e75d 100644 --- a/ee/connectors/msgcodec/msgcodec.py +++ b/ee/connectors/msgcodec/msgcodec.py @@ -668,14 +668,6 @@ class MessageCodec(Codec): state=self.read_string(reader) ) - if message_id == 83: - return ReplaceVCSS( - id=self.read_uint(reader), - styles=self.read_string(reader), - sheet_id=self.read_uint(reader), - base_url=self.read_string(reader) - ) - if message_id == 107: return IOSBatchMeta( timestamp=self.read_uint(reader), diff --git a/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts b/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts index 9c51e56f1..33bf9d2c5 100644 --- a/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts +++ b/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts @@ -10,7 +10,6 @@ import type { RawAdoptedSsInsertRule, RawAdoptedSsReplaceURLBased, RawAdoptedSsReplace, - RawReplaceVcss, } from './raw' import type { TrackerMessage } from './tracker' import translate from './tracker' @@ -66,12 +65,6 @@ const resolvers = { text: resolveCSS(msg.baseURL, msg.text), tp: "adopted_ss_replace" }), - "replace_vcss_url_based": (msg: RawReplaceVcss): RawReplaceVcss => - ({ - ...msg, - styles: resolveCSS(msg.baseURL, msg.styles), - tp: "replace_vcss", - }) } as const type ResolvableType = keyof typeof resolvers diff --git a/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts b/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts index fdd34bc3e..f459c9369 100644 --- a/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts +++ b/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts @@ -538,20 +538,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 83: { - const id = this.readUint(); if (id === null) { return resetPointer() } - const styles = this.readString(); if (styles === null) { return resetPointer() } - const sheetID = this.readUint(); if (sheetID === null) { return resetPointer() } - const baseURL = this.readString(); if (baseURL === null) { return resetPointer() } - return { - tp: "replace_vcss", - id, - styles, - sheetID, - baseURL, - }; - } - case 90: { const timestamp = this.readUint(); if (timestamp === null) { return resetPointer() } const projectID = this.readUint(); if (projectID === null) { return resetPointer() } diff --git a/frontend/app/player/MessageDistributor/messages/message.ts b/frontend/app/player/MessageDistributor/messages/message.ts index a731c2462..4b82c27e7 100644 --- a/frontend/app/player/MessageDistributor/messages/message.ts +++ b/frontend/app/player/MessageDistributor/messages/message.ts @@ -49,7 +49,6 @@ import type { RawAdoptedSsAddOwner, RawAdoptedSsRemoveOwner, RawZustand, - RawReplaceVcss, RawIosSessionStart, RawIosCustomEvent, RawIosScreenChanges, @@ -152,8 +151,6 @@ export type AdoptedSsRemoveOwner = RawAdoptedSsRemoveOwner & Timed export type Zustand = RawZustand & Timed -export type ReplaceVcss = RawReplaceVcss & Timed - export type IosSessionStart = RawIosSessionStart & Timed export type IosCustomEvent = RawIosCustomEvent & Timed diff --git a/frontend/app/player/MessageDistributor/messages/raw.ts b/frontend/app/player/MessageDistributor/messages/raw.ts index 963d1a3f9..69ef5877f 100644 --- a/frontend/app/player/MessageDistributor/messages/raw.ts +++ b/frontend/app/player/MessageDistributor/messages/raw.ts @@ -307,14 +307,6 @@ export interface RawZustand { state: string, } -export interface RawReplaceVcss { - tp: "replace_vcss", - id: number, - styles: string, - sheetID: number, - baseURL: string, -} - export interface RawIosSessionStart { tp: "ios_session_start", timestamp: number, @@ -386,4 +378,4 @@ export interface RawIosNetworkCall { } -export type RawMessage = RawTimestamp | RawSetPageLocation | RawSetViewportSize | RawSetViewportScroll | RawCreateDocument | RawCreateElementNode | RawCreateTextNode | RawMoveNode | RawRemoveNode | RawSetNodeAttribute | RawRemoveNodeAttribute | RawSetNodeData | RawSetCssData | RawSetNodeScroll | RawSetInputValue | RawSetInputChecked | RawMouseMove | RawConsoleLog | RawCssInsertRule | RawCssDeleteRule | RawFetch | RawProfiler | RawOTable | RawRedux | RawVuex | RawMobX | RawNgRx | RawGraphQl | RawPerformanceTrack | RawConnectionInformation | RawSetPageVisibility | RawLongTask | RawSetNodeAttributeURLBased | RawSetCssDataURLBased | RawCssInsertRuleURLBased | RawMouseClick | RawCreateIFrameDocument | RawAdoptedSsReplaceURLBased | RawAdoptedSsReplace | RawAdoptedSsInsertRuleURLBased | RawAdoptedSsInsertRule | RawAdoptedSsDeleteRule | RawAdoptedSsAddOwner | RawAdoptedSsRemoveOwner | RawZustand | RawReplaceVcss | RawIosSessionStart | RawIosCustomEvent | RawIosScreenChanges | RawIosClickEvent | RawIosPerformanceEvent | RawIosLog | RawIosNetworkCall; +export type RawMessage = RawTimestamp | RawSetPageLocation | RawSetViewportSize | RawSetViewportScroll | RawCreateDocument | RawCreateElementNode | RawCreateTextNode | RawMoveNode | RawRemoveNode | RawSetNodeAttribute | RawRemoveNodeAttribute | RawSetNodeData | RawSetCssData | RawSetNodeScroll | RawSetInputValue | RawSetInputChecked | RawMouseMove | RawConsoleLog | RawCssInsertRule | RawCssDeleteRule | RawFetch | RawProfiler | RawOTable | RawRedux | RawVuex | RawMobX | RawNgRx | RawGraphQl | RawPerformanceTrack | RawConnectionInformation | RawSetPageVisibility | RawLongTask | RawSetNodeAttributeURLBased | RawSetCssDataURLBased | RawCssInsertRuleURLBased | RawMouseClick | RawCreateIFrameDocument | RawAdoptedSsReplaceURLBased | RawAdoptedSsReplace | RawAdoptedSsInsertRuleURLBased | RawAdoptedSsInsertRule | RawAdoptedSsDeleteRule | RawAdoptedSsAddOwner | RawAdoptedSsRemoveOwner | RawZustand | RawIosSessionStart | RawIosCustomEvent | RawIosScreenChanges | RawIosClickEvent | RawIosPerformanceEvent | RawIosLog | RawIosNetworkCall; diff --git a/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts b/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts index 9ff0dd332..1cc6af93d 100644 --- a/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts +++ b/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts @@ -62,7 +62,6 @@ export const TP_MAP = { 76: "adopted_ss_add_owner", 77: "adopted_ss_remove_owner", 79: "zustand", - 83: "replace_vcss", 90: "ios_session_start", 93: "ios_custom_event", 96: "ios_screen_changes", diff --git a/frontend/app/player/MessageDistributor/messages/tracker.ts b/frontend/app/player/MessageDistributor/messages/tracker.ts index 44c7e7e79..7381670c7 100644 --- a/frontend/app/player/MessageDistributor/messages/tracker.ts +++ b/frontend/app/player/MessageDistributor/messages/tracker.ts @@ -389,16 +389,8 @@ type TrZustand = [ state: string, ] -type TrReplaceVCSS = [ - type: 83, - id: number, - styles: string, - sheetID: number, - baseURL: string, -] - -export type TrackerMessage = TrBatchMetadata | TrPartitionedMessage | TrTimestamp | TrSetPageLocation | TrSetViewportSize | TrSetViewportScroll | TrCreateDocument | TrCreateElementNode | TrCreateTextNode | TrMoveNode | TrRemoveNode | TrSetNodeAttribute | TrRemoveNodeAttribute | TrSetNodeData | TrSetNodeScroll | TrSetInputTarget | TrSetInputValue | TrSetInputChecked | TrMouseMove | TrConsoleLog | TrPageLoadTiming | TrPageRenderTiming | TrJSException | TrRawCustomEvent | TrUserID | TrUserAnonymousID | TrMetadata | TrCSSInsertRule | TrCSSDeleteRule | TrFetch | TrProfiler | TrOTable | TrStateAction | TrRedux | TrVuex | TrMobX | TrNgRx | TrGraphQL | TrPerformanceTrack | TrResourceTiming | TrConnectionInformation | TrSetPageVisibility | TrLongTask | TrSetNodeAttributeURLBased | TrSetCSSDataURLBased | TrTechnicalInfo | TrCustomIssue | TrCSSInsertRuleURLBased | TrMouseClick | TrCreateIFrameDocument | TrAdoptedSSReplaceURLBased | TrAdoptedSSInsertRuleURLBased | TrAdoptedSSDeleteRule | TrAdoptedSSAddOwner | TrAdoptedSSRemoveOwner | TrZustand | TrReplaceVCSS +export type TrackerMessage = TrBatchMetadata | TrPartitionedMessage | TrTimestamp | TrSetPageLocation | TrSetViewportSize | TrSetViewportScroll | TrCreateDocument | TrCreateElementNode | TrCreateTextNode | TrMoveNode | TrRemoveNode | TrSetNodeAttribute | TrRemoveNodeAttribute | TrSetNodeData | TrSetNodeScroll | TrSetInputTarget | TrSetInputValue | TrSetInputChecked | TrMouseMove | TrConsoleLog | TrPageLoadTiming | TrPageRenderTiming | TrJSException | TrRawCustomEvent | TrUserID | TrUserAnonymousID | TrMetadata | TrCSSInsertRule | TrCSSDeleteRule | TrFetch | TrProfiler | TrOTable | TrStateAction | TrRedux | TrVuex | TrMobX | TrNgRx | TrGraphQL | TrPerformanceTrack | TrResourceTiming | TrConnectionInformation | TrSetPageVisibility | TrLongTask | TrSetNodeAttributeURLBased | TrSetCSSDataURLBased | TrTechnicalInfo | TrCustomIssue | TrCSSInsertRuleURLBased | TrMouseClick | TrCreateIFrameDocument | TrAdoptedSSReplaceURLBased | TrAdoptedSSInsertRuleURLBased | TrAdoptedSSDeleteRule | TrAdoptedSSAddOwner | TrAdoptedSSRemoveOwner | TrZustand export default function translate(tMsg: TrackerMessage): RawMessage | null { switch(tMsg[0]) { @@ -773,16 +765,6 @@ export default function translate(tMsg: TrackerMessage): RawMessage | null { } } - case 83: { - return { - tp: "replace_vcss", - id: tMsg[1], - styles: tMsg[2], - sheetID: tMsg[3], - baseURL: tMsg[4], - } - } - default: return null } diff --git a/mobs/messages.rb b/mobs/messages.rb index 5d43ee8d9..a3a7111de 100644 --- a/mobs/messages.rb +++ b/mobs/messages.rb @@ -44,7 +44,7 @@ message 1, 'SessionStart', :tracker => false, :replayer => false do string 'UserCountry' string 'UserID' end -# message 2, 'CreateDocument', do +## message 2, 'CreateDocument', do # end message 3, 'SessionEnd', :tracker => false, :replayer => false do uint 'Timestamp' @@ -62,7 +62,7 @@ message 6, 'SetViewportScroll' do int 'X' int 'Y' end -# Depricated sinse tracker 3.6.0 in favor of CreateDocument(id=2) +# (should be) Depricated sinse tracker ?.?.? in favor of CreateDocument(id=2) # in order to use Document as a default root node instead of the documentElement message 7, 'CreateDocument' do end @@ -238,8 +238,6 @@ message 36, 'CustomEvent', :tracker => false, :replayer => false do string 'Name' string 'Payload' end - - message 37, 'CSSInsertRule' do uint 'ID' string 'Rule' @@ -249,7 +247,6 @@ message 38, 'CSSDeleteRule' do uint 'ID' uint 'Index' end - message 39, 'Fetch' do string 'Method' string 'URL' @@ -265,7 +262,6 @@ message 40, 'Profiler' do string 'Args' string 'Result' end - message 41, 'OTable' do string 'Key' string 'Value' @@ -278,7 +274,6 @@ message 43, 'StateActionEvent', :tracker => false, :replayer => false do uint 'Timestamp' string 'Type' end - message 44, 'Redux' do string 'Action' string 'State' @@ -363,6 +358,7 @@ message 56, 'PerformanceTrackAggr', :tracker => false, :replayer => false do uint 'AvgUsedJSHeapSize' uint 'MaxUsedJSHeapSize' end +## 57 58 message 59, 'LongTask' do uint 'Timestamp' uint 'Duration' @@ -400,6 +396,7 @@ message 64, 'CustomIssue', :replayer => false do string 'Name' string 'Payload' end +## 65 message 66, 'AssetCache', :replayer => false, :tracker => false do string 'URL' end @@ -409,6 +406,7 @@ message 67, 'CSSInsertRuleURLBased' do uint 'Index' string 'BaseURL' end +## 68 message 69, 'MouseClick' do uint 'ID' uint 'HesitationTime' @@ -416,13 +414,13 @@ message 69, 'MouseClick' do string 'Selector' end -# Since 3.4.0 +# Since 3.4.0 //also used for ShadowDom. TODO:remane to CreateRoot message 70, 'CreateIFrameDocument' do uint 'FrameID' uint 'ID' end -#Since 3.6.0 AdoptedStyleSheets +#Since 4.0.0 AdoptedStyleSheets etc message 71, 'AdoptedSSReplaceURLBased' do uint 'SheetID' string 'Text' @@ -455,15 +453,16 @@ message 77, 'AdoptedSSRemoveOwner' do uint 'SheetID' uint 'ID' end - +#Since 4.0.1 +# message 78, 'ReplaceVCSSURLBased' do +# uint 'SheetID' +# uint 'Index' +# string 'Styles' +# string 'BaseURL' +# end message 79, 'Zustand' do string 'Mutation' string 'State' end -message 83, 'ReplaceVCSS' do - uint 'ID' - string 'Styles' - uint 'SheetID' - string 'BaseURL' -end +# 80 -- 90 reserved \ No newline at end of file diff --git a/tracker/tracker/src/common/messages.gen.ts b/tracker/tracker/src/common/messages.gen.ts index c4da7c4b5..4e2afe778 100644 --- a/tracker/tracker/src/common/messages.gen.ts +++ b/tracker/tracker/src/common/messages.gen.ts @@ -58,7 +58,6 @@ export declare const enum Type { AdoptedSSAddOwner = 76, AdoptedSSRemoveOwner = 77, Zustand = 79, - ReplaceVCSS = 83, } @@ -447,14 +446,6 @@ export type Zustand = [ /*state:*/ string, ] -export type ReplaceVCSS = [ - /*type:*/ Type.ReplaceVCSS, - /*id:*/ number, - /*styles:*/ string, - /*sheetID:*/ number, - /*baseURL:*/ string, -] - -type Message = BatchMetadata | PartitionedMessage | Timestamp | SetPageLocation | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | ConsoleLog | PageLoadTiming | PageRenderTiming | JSException | RawCustomEvent | UserID | UserAnonymousID | Metadata | CSSInsertRule | CSSDeleteRule | Fetch | Profiler | OTable | StateAction | Redux | Vuex | MobX | NgRx | GraphQL | PerformanceTrack | ResourceTiming | ConnectionInformation | SetPageVisibility | LongTask | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | CSSInsertRuleURLBased | MouseClick | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner | Zustand | ReplaceVCSS +type Message = BatchMetadata | PartitionedMessage | Timestamp | SetPageLocation | SetViewportSize | SetViewportScroll | CreateDocument | CreateElementNode | CreateTextNode | MoveNode | RemoveNode | SetNodeAttribute | RemoveNodeAttribute | SetNodeData | SetNodeScroll | SetInputTarget | SetInputValue | SetInputChecked | MouseMove | ConsoleLog | PageLoadTiming | PageRenderTiming | JSException | RawCustomEvent | UserID | UserAnonymousID | Metadata | CSSInsertRule | CSSDeleteRule | Fetch | Profiler | OTable | StateAction | Redux | Vuex | MobX | NgRx | GraphQL | PerformanceTrack | ResourceTiming | ConnectionInformation | SetPageVisibility | LongTask | SetNodeAttributeURLBased | SetCSSDataURLBased | TechnicalInfo | CustomIssue | CSSInsertRuleURLBased | MouseClick | CreateIFrameDocument | AdoptedSSReplaceURLBased | AdoptedSSInsertRuleURLBased | AdoptedSSDeleteRule | AdoptedSSAddOwner | AdoptedSSRemoveOwner | Zustand export default Message diff --git a/tracker/tracker/src/main/app/messages.gen.ts b/tracker/tracker/src/main/app/messages.gen.ts index 1853d0fb3..ce924a918 100644 --- a/tracker/tracker/src/main/app/messages.gen.ts +++ b/tracker/tracker/src/main/app/messages.gen.ts @@ -719,18 +719,3 @@ export function Zustand( ] } -export function ReplaceVCSS( - id: number, - styles: string, - sheetID: number, - baseURL: string, -): Messages.ReplaceVCSS { - return [ - Messages.Type.ReplaceVCSS, - id, - styles, - sheetID, - baseURL, - ] -} - diff --git a/tracker/tracker/src/main/modules/cssrules.ts b/tracker/tracker/src/main/modules/cssrules.ts index d7f12652a..159f9c25d 100644 --- a/tracker/tracker/src/main/modules/cssrules.ts +++ b/tracker/tracker/src/main/modules/cssrules.ts @@ -1,10 +1,5 @@ import type App from '../app/index.js' -import { - CSSInsertRuleURLBased, - CSSDeleteRule, - TechnicalInfo, - ReplaceVCSS, -} from '../app/messages.gen.js' +import { CSSInsertRuleURLBased, CSSDeleteRule, TechnicalInfo } from '../app/messages.gen.js' import { hasTag } from '../app/guards.js' export default function (app: App | null) { @@ -32,28 +27,25 @@ export default function (app: App | null) { } // else error? }) - const replaceVirtualCss = app.safe((ctx: CSSGroupingRule) => { - let uppermostRuleset = ctx.parentRule - while (uppermostRuleset?.parentRule) { - uppermostRuleset = uppermostRuleset.parentRule + const replaceGroupingRule = app.safe((ctx: CSSGroupingRule) => { + let topmostRule: CSSRule = ctx + while (topmostRule.parentRule) { + topmostRule = topmostRule.parentRule } - if (uppermostRuleset?.parentStyleSheet?.ownerNode) { - const entireStyle = uppermostRuleset.cssText - const parentNodeID = app.nodes.getID(uppermostRuleset.parentStyleSheet.ownerNode) - const ruleList = uppermostRuleset.parentStyleSheet.cssRules - let id = -1 - for (let i = 0; i < ruleList.length; i++) { - const rule = ruleList.item(i) - if (rule === uppermostRuleset) { - id = i - break - } + if (topmostRule.parentStyleSheet?.ownerNode) { + const entireStyle = topmostRule.cssText + const nodeID = app.nodes.getID(topmostRule.parentStyleSheet.ownerNode) + if (nodeID === undefined) { + return } - if (parentNodeID && id >= 0) { - app.send(ReplaceVCSS(parentNodeID, entireStyle, id, app.getBaseHref())) + const ruleList = topmostRule.parentStyleSheet.cssRules + const idx = Array.from(ruleList).indexOf(topmostRule) + if (idx >= 0) { + app.send(CSSDeleteRule(nodeID, idx)) + app.send(CSSInsertRuleURLBased(nodeID, entireStyle, idx, app.getBaseHref())) } } else { - app.debug.error('Owner Node not found') + app.debug.error('Owner Node not found for the rule', topmostRule) } }) @@ -73,21 +65,17 @@ export default function (app: App | null) { context.CSSGroupingRule.prototype.insertRule = function (rule: string, index = 0) { const result = groupInsertRule.call(this, rule, index) as number - - replaceVirtualCss(this) - + replaceGroupingRule(this) return result } context.CSSGroupingRule.prototype.deleteRule = function (index = 0) { const result = groupDeleteRule.call(this, index) as number - - replaceVirtualCss(this) - + replaceGroupingRule(this) return result } } - sheet.patchContext(window) + patchContext(window) app.observer.attachContextCallback(patchContext) app.nodes.attachNodeCallback((node: Node): void => { diff --git a/tracker/tracker/src/webworker/MessageEncoder.gen.ts b/tracker/tracker/src/webworker/MessageEncoder.gen.ts index a97e54ccc..b646fd6ff 100644 --- a/tracker/tracker/src/webworker/MessageEncoder.gen.ts +++ b/tracker/tracker/src/webworker/MessageEncoder.gen.ts @@ -234,10 +234,6 @@ export default class MessageEncoder extends PrimitiveEncoder { return this.string(msg[1]) && this.string(msg[2]) break - case Messages.Type.ReplaceVCSS: - return this.uint(msg[1]) && this.string(msg[2]) && this.uint(msg[3]) && this.string(msg[4]) - break - } }