Skip to content

Commit dec4c9f

Browse files
committed
refactor bypass/breackpoint storage to allow more than one traceId's per session
1 parent 5143920 commit dec4c9f

17 files changed

+190
-86
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ If you're web developer and want to assess implementation correctness - this too
3434
- requestIdleCallback
3535
- cancelIdleCallback
3636

37-
##### Note:
38-
39-
- while measuring performance of your code – consider disabling this extension as it may affect the results.
37+
> [!NOTE]
38+
> While measuring performance of your code – consider disabling this extension as it may affect the results.
4039
4140
<details>
4241
<summary> <strong>Example</strong> </summary>

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"imports": {
3737
"esbuild": "https://deno.land/x/[email protected]/mod.js",
3838
"@luca/esbuild-deno-loader": "jsr:@luca/[email protected]",
39-
"esbuild-svelte": "npm:[email protected].0",
39+
"esbuild-svelte": "npm:[email protected].2",
4040
"svelte-preprocess": "npm:[email protected]",
4141

4242
"@std/expect": "jsr:@std/expect@^1.0.15",

deno.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-monitor-cs-isolated.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@ import {
66
windowPost,
77
} from './api/communication.ts';
88
import { getSettings, onSettingsChange } from './api/settings.ts';
9+
import { getSession, onSessionChange } from './api/session.ts';
910

1011
getSettings().then((settings) => {
11-
windowPost({ msg: EMsg.SETTINGS, settings: settings });
12+
windowPost({ msg: EMsg.SETTINGS, settings });
1213

1314
onSettingsChange((newValue) => {
1415
windowPost({ msg: EMsg.SETTINGS, settings: newValue });
1516
});
1617
});
1718

19+
getSession().then((session) => {
20+
windowPost({ msg: EMsg.SESSION, session });
21+
22+
onSessionChange((newValue) => {
23+
windowPost({ msg: EMsg.SESSION, session: newValue });
24+
});
25+
});
26+
1827
portListen(windowPost);
1928
windowListen(runtimePost);
2029

2130
runtimePost({ msg: EMsg.CONTENT_SCRIPT_LOADED });
31+
32+
__development__ && console.log('api-monitor-cs-isolated.ts');

src/api-monitor-cs-main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
runMediaCommand,
99
runTimerCommand,
1010
setSettings,
11+
setTracePoints,
1112
type TTelemetry,
1213
} from './wrapper/Wrapper.ts';
1314
import diff from './api/diff.ts';
@@ -72,7 +73,9 @@ windowListen((o) => {
7273
runTimerCommand(o.type, o.handler);
7374
} else if (o.msg === EMsg.MEDIA_COMMAND) {
7475
runMediaCommand(o.mediaId, o.cmd, o.property);
76+
} else if (o.msg === EMsg.SESSION) {
77+
setTracePoints(o.session);
7578
}
7679
});
7780

78-
__development__ && console.debug('cs-main.ts');
81+
__development__ && console.debug('api-monitor-cs-main.ts');

src/api-monitor-devtools.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EMsg, portPost } from './api/communication.ts';
22
import { getSettings, setSettings } from './api/settings.ts';
3+
import { enableSessionInContentScript } from './api/session.ts';
34

45
// tabId may be null if user opened the devtools of the devtools
56
if (chrome.devtools.inspectedWindow.tabId !== null) {
@@ -21,4 +22,6 @@ if (chrome.devtools.inspectedWindow.tabId !== null) {
2122
});
2223
},
2324
);
25+
26+
enableSessionInContentScript();
2427
}

src/api/communication.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { TTelemetry } from '../wrapper/Wrapper.ts';
1717
import type { TSettings } from './settings.ts';
1818
import type { TMediaCommand } from '../wrapper/MediaWrapper.ts';
1919
import type { Delta } from 'jsondiffpatch';
20+
import type { TSession } from './session.ts';
2021

2122
let port: chrome.runtime.Port | null = null;
2223
export function portPost(payload: TMsgOptions) {
@@ -101,57 +102,63 @@ export enum EMsg {
101102
MEDIA_COMMAND,
102103
RESET_WRAPPER_HISTORY,
103104
TIMER_COMMAND,
105+
SESSION,
104106
}
105107

106-
export interface TMsgStartObserve {
108+
export interface IMsgStartObserve {
107109
msg: EMsg.START_OBSERVE;
108110
}
109-
export interface TMsgStopObserve {
111+
export interface IMsgStopObserve {
110112
msg: EMsg.STOP_OBSERVE;
111113
}
112-
export interface TMsgResetHistory {
114+
export interface IMsgResetHistory {
113115
msg: EMsg.RESET_WRAPPER_HISTORY;
114116
}
115-
export interface TMsgTimerCommand {
117+
export interface IMsgTimerCommand {
116118
msg: EMsg.TIMER_COMMAND;
117119
type: ETimerType;
118120
handler: number;
119121
}
120-
export interface TMsgLoaded {
122+
export interface IMsgLoaded {
121123
msg: EMsg.CONTENT_SCRIPT_LOADED;
122124
}
123-
export interface TMsgTelemetry {
125+
export interface IMsgTelemetry {
124126
msg: EMsg.TELEMETRY;
125127
timeOfCollection: number;
126128
telemetry: TTelemetry;
127129
}
128-
export interface TMsgTelemetryDelta {
130+
export interface IMsgTelemetryDelta {
129131
msg: EMsg.TELEMETRY_DELTA;
130132
timeOfCollection: number;
131133
telemetryDelta: Delta;
132134
}
133-
export interface TMsgTelemetryAcknowledged {
135+
export interface IMsgTelemetryAcknowledged {
134136
msg: EMsg.TELEMETRY_ACKNOWLEDGED;
135137
timeOfCollection: number;
136138
}
137-
export interface TMsgSettings {
139+
export interface IMsgSettings {
138140
msg: EMsg.SETTINGS;
139141
settings: TSettings;
140142
}
141-
export interface TMsgMediaCommand {
143+
export interface IMsgMediaCommand {
142144
msg: EMsg.MEDIA_COMMAND;
143145
mediaId: string;
144146
cmd: TMediaCommand;
145147
property?: keyof HTMLMediaElement;
146148
}
149+
export interface IMsgSession {
150+
msg: EMsg.SESSION;
151+
session: TSession;
152+
}
147153
export type TMsgOptions =
148-
| TMsgTelemetry
149-
| TMsgTelemetryDelta
150-
| TMsgTelemetryAcknowledged
151-
| TMsgStartObserve
152-
| TMsgStopObserve
153-
| TMsgLoaded
154-
| TMsgResetHistory
155-
| TMsgTimerCommand
156-
| TMsgSettings
157-
| TMsgMediaCommand;
154+
| IMsgTelemetry
155+
| IMsgTelemetryDelta
156+
| IMsgTelemetryAcknowledged
157+
| IMsgStartObserve
158+
| IMsgStopObserve
159+
| IMsgLoaded
160+
| IMsgResetHistory
161+
| IMsgTimerCommand
162+
| IMsgSettings
163+
| IMsgMediaCommand
164+
| IMsgSession;

src/api/hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sha256 } from '@noble/hashes/sha2';
22
import { bytesToHex } from '@noble/hashes/utils';
33

4-
const HASH_STRING_LENGTH = 64;
4+
export const HASH_STRING_LENGTH = 64;
55

66
export function hashString(str: string) {
77
return (

src/api/session.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const SESSION_VERSION = '1.2.0';
2+
3+
export type TSession = typeof DEFAULT_SESSION;
4+
type TSessionProperty = Partial<TSession>;
5+
const DEFAULT_SESSION = {
6+
debug: <string[]> [],
7+
bypass: <string[]> [],
8+
};
9+
10+
export function enableSessionInContentScript() {
11+
return chrome.storage.session.setAccessLevel({
12+
accessLevel: 'TRUSTED_AND_UNTRUSTED_CONTEXTS',
13+
});
14+
}
15+
16+
export async function getSession(): Promise<TSession> {
17+
let store = await chrome.storage.session.get([SESSION_VERSION]);
18+
const isEmpty = !Object.keys(store).length;
19+
20+
if (isEmpty) {
21+
await chrome.storage.session.clear(); // rid off previous version settings
22+
await chrome.storage.session.set({ [SESSION_VERSION]: DEFAULT_SESSION });
23+
store = await chrome.storage.session.get([SESSION_VERSION]);
24+
}
25+
26+
return store[SESSION_VERSION];
27+
}
28+
29+
export async function setSession(value: TSessionProperty) {
30+
const store = await chrome.storage.session.get([SESSION_VERSION]);
31+
32+
Object.assign(store[SESSION_VERSION], value);
33+
34+
return await chrome.storage.session.set(store);
35+
}
36+
37+
export function onSessionChange(
38+
callback: (newValue: TSession, oldValue: TSession) => void,
39+
) {
40+
chrome.storage.session.onChanged.addListener((change) => {
41+
if (
42+
change && change[SESSION_VERSION] && change[SESSION_VERSION].newValue
43+
) {
44+
callback(
45+
change[SESSION_VERSION].newValue,
46+
change[SESSION_VERSION].oldValue,
47+
);
48+
}
49+
});
50+
}

src/api/settings.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type TSettingsPanel = {
3535
export type TSettings = typeof DEFAULT_SETTINGS;
3636
export type TSettingsProperty = Partial<TSettings>;
3737

38-
const SETTINGS_VERSION = '1.0.7';
38+
const SETTINGS_VERSION = '1.2.0';
3939
export const DEFAULT_PANELS: TSettingsPanel[] = [
4040
{ key: 'media', label: 'Media', visible: true, wrap: null },
4141
{ key: 'activeTimers', label: 'Active Timers', visible: true, wrap: null },
@@ -129,8 +129,6 @@ export const DEFAULT_SETTINGS = {
129129
sortCancelIdleCallback: DEFAULT_SORT_CIC,
130130
paused: false,
131131
devtoolsPanelShown: false,
132-
trace4Debug: <string | null> null,
133-
trace4Bypass: <string | null> null,
134132
wrapperCallstackType: EWrapperCallstackType.SHORT,
135133
};
136134

0 commit comments

Comments
 (0)