@flrande/bak-extension 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.bak-e2e-build-stamp +1 -1
- package/dist/background.global.js +692 -266
- package/dist/content.global.js +83 -22
- package/dist/manifest.json +1 -1
- package/package.json +2 -2
- package/public/manifest.json +1 -1
- package/src/background.ts +728 -202
- package/src/content.ts +93 -22
- package/src/network-debugger.ts +1 -1
- package/src/session-binding-storage.ts +50 -68
- package/src/{workspace.ts → session-binding.ts} +228 -213
package/dist/content.global.js
CHANGED
|
@@ -236,6 +236,7 @@
|
|
|
236
236
|
var performanceBaselineMs = 0;
|
|
237
237
|
var pageLoadedAt = Math.round(performance.timeOrigin || Date.now());
|
|
238
238
|
var lastMutationAt = Date.now();
|
|
239
|
+
var DISCOVERY_GLOBAL_PATTERN = /(data|table|json|state|store|market|quote|flow|row|timestamp|snapshot|book|signal)/i;
|
|
239
240
|
function isHtmlElement(node) {
|
|
240
241
|
if (!node) {
|
|
241
242
|
return false;
|
|
@@ -1606,26 +1607,35 @@
|
|
|
1606
1607
|
shadowPath: [...contextState.shadowPath]
|
|
1607
1608
|
};
|
|
1608
1609
|
}
|
|
1609
|
-
function
|
|
1610
|
-
const regexes = (patterns ?? [
|
|
1611
|
-
(
|
|
1612
|
-
|
|
1613
|
-
|
|
1610
|
+
function timestampCandidateMatchesFromText(text, patterns) {
|
|
1611
|
+
const regexes = (patterns ?? [
|
|
1612
|
+
String.raw`\b20\d{2}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?\b`,
|
|
1613
|
+
String.raw`\b20\d{2}-\d{2}-\d{2}\b`,
|
|
1614
|
+
String.raw`\b20\d{2}\/\d{2}\/\d{2}\b`
|
|
1615
|
+
]).map((pattern) => new RegExp(pattern, "gi"));
|
|
1616
|
+
const collected = /* @__PURE__ */ new Map();
|
|
1614
1617
|
for (const regex of regexes) {
|
|
1615
1618
|
for (const match of text.matchAll(regex)) {
|
|
1616
|
-
|
|
1617
|
-
|
|
1619
|
+
const value = match[0];
|
|
1620
|
+
if (!value) {
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
const index = match.index ?? text.indexOf(value);
|
|
1624
|
+
const start = Math.max(0, index - 28);
|
|
1625
|
+
const end = Math.min(text.length, index + value.length + 28);
|
|
1626
|
+
const context = text.slice(start, end).replace(/\s+/g, " ").trim();
|
|
1627
|
+
const key = `${value}::${context}`;
|
|
1628
|
+
if (!collected.has(key)) {
|
|
1629
|
+
collected.set(key, { value, context });
|
|
1618
1630
|
}
|
|
1619
1631
|
}
|
|
1620
1632
|
}
|
|
1621
|
-
return [...collected];
|
|
1633
|
+
return [...collected.values()];
|
|
1622
1634
|
}
|
|
1623
1635
|
function listInlineScripts() {
|
|
1624
1636
|
return Array.from(document.scripts).filter((script) => !script.src).map((script) => {
|
|
1625
1637
|
const content = script.textContent ?? "";
|
|
1626
|
-
const suspectedVars = [...content.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*(
|
|
1627
|
-
(match) => match[1] ?? ""
|
|
1628
|
-
).filter(Boolean);
|
|
1638
|
+
const suspectedVars = [...content.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g)].map((match) => match[1] ?? "").filter((candidate) => DISCOVERY_GLOBAL_PATTERN.test(candidate));
|
|
1629
1639
|
return { content, suspectedVars };
|
|
1630
1640
|
});
|
|
1631
1641
|
}
|
|
@@ -1913,6 +1923,20 @@
|
|
|
1913
1923
|
}
|
|
1914
1924
|
return segments;
|
|
1915
1925
|
};
|
|
1926
|
+
const buildPathExpression = (path) => {
|
|
1927
|
+
const segments = parsePath(path);
|
|
1928
|
+
return segments
|
|
1929
|
+
.map((segment, index) => {
|
|
1930
|
+
if (typeof segment === 'number') {
|
|
1931
|
+
return '[' + segment + ']';
|
|
1932
|
+
}
|
|
1933
|
+
if (index === 0) {
|
|
1934
|
+
return segment;
|
|
1935
|
+
}
|
|
1936
|
+
return '.' + segment;
|
|
1937
|
+
})
|
|
1938
|
+
.join('');
|
|
1939
|
+
};
|
|
1916
1940
|
const readPath = (targetWindow, path) => {
|
|
1917
1941
|
const segments = parsePath(path);
|
|
1918
1942
|
let current = targetWindow;
|
|
@@ -1924,6 +1948,34 @@
|
|
|
1924
1948
|
}
|
|
1925
1949
|
return current;
|
|
1926
1950
|
};
|
|
1951
|
+
const resolveExtractValue = (targetWindow, path, resolver) => {
|
|
1952
|
+
const strategy = resolver === 'globalThis' || resolver === 'lexical' ? resolver : 'auto';
|
|
1953
|
+
const lexicalExpression = buildPathExpression(path);
|
|
1954
|
+
const readLexical = () => {
|
|
1955
|
+
try {
|
|
1956
|
+
return targetWindow.eval(lexicalExpression);
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
if (error instanceof ReferenceError) {
|
|
1959
|
+
throw { code: 'E_NOT_FOUND', message: 'path not found: ' + path };
|
|
1960
|
+
}
|
|
1961
|
+
throw error;
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
if (strategy === 'globalThis') {
|
|
1965
|
+
return { resolver: 'globalThis', value: readPath(targetWindow, path) };
|
|
1966
|
+
}
|
|
1967
|
+
if (strategy === 'lexical') {
|
|
1968
|
+
return { resolver: 'lexical', value: readLexical() };
|
|
1969
|
+
}
|
|
1970
|
+
try {
|
|
1971
|
+
return { resolver: 'globalThis', value: readPath(targetWindow, path) };
|
|
1972
|
+
} catch (error) {
|
|
1973
|
+
if (!error || typeof error !== 'object' || error.code !== 'E_NOT_FOUND') {
|
|
1974
|
+
throw error;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
return { resolver: 'lexical', value: readLexical() };
|
|
1978
|
+
};
|
|
1927
1979
|
const buildScopeTargets = () => {
|
|
1928
1980
|
if (payload.scope === 'main') {
|
|
1929
1981
|
return [{
|
|
@@ -1943,7 +1995,7 @@
|
|
|
1943
1995
|
};
|
|
1944
1996
|
const toResult = async (target) => {
|
|
1945
1997
|
if (action === 'globals') {
|
|
1946
|
-
const keys = Object.keys(target.targetWindow).filter((key) =>
|
|
1998
|
+
const keys = Object.keys(target.targetWindow).filter((key) => ${DISCOVERY_GLOBAL_PATTERN}.test(key)).slice(0, 50);
|
|
1947
1999
|
return { url: target.url, framePath: target.framePath, value: keys };
|
|
1948
2000
|
}
|
|
1949
2001
|
if (action === 'eval') {
|
|
@@ -1951,8 +2003,9 @@
|
|
|
1951
2003
|
return { url: target.url, framePath: target.framePath, value: serialized.value, bytes: serialized.bytes };
|
|
1952
2004
|
}
|
|
1953
2005
|
if (action === 'extract') {
|
|
1954
|
-
const
|
|
1955
|
-
|
|
2006
|
+
const extracted = resolveExtractValue(target.targetWindow, payload.path, payload.resolver);
|
|
2007
|
+
const serialized = serializeValue(extracted.value, payload.maxBytes);
|
|
2008
|
+
return { url: target.url, framePath: target.framePath, value: serialized.value, bytes: serialized.bytes, resolver: extracted.resolver };
|
|
1956
2009
|
}
|
|
1957
2010
|
if (action === 'fetch') {
|
|
1958
2011
|
const headers = { ...(payload.headers || {}) };
|
|
@@ -2074,6 +2127,7 @@
|
|
|
2074
2127
|
function pageExtract(path, params) {
|
|
2075
2128
|
return runPageWorldRequest("extract", {
|
|
2076
2129
|
path,
|
|
2130
|
+
resolver: typeof params.resolver === "string" ? params.resolver : void 0,
|
|
2077
2131
|
scope: resolveScope(params),
|
|
2078
2132
|
maxBytes: typeof params.maxBytes === "number" ? params.maxBytes : void 0,
|
|
2079
2133
|
framePath: pageWorldFramePath()
|
|
@@ -2094,7 +2148,7 @@
|
|
|
2094
2148
|
});
|
|
2095
2149
|
}
|
|
2096
2150
|
async function globalsPreview() {
|
|
2097
|
-
return Object.keys(window).filter((key) =>
|
|
2151
|
+
return Object.keys(window).filter((key) => DISCOVERY_GLOBAL_PATTERN.test(key)).slice(0, 50);
|
|
2098
2152
|
}
|
|
2099
2153
|
async function collectInspectionState(params = {}) {
|
|
2100
2154
|
const rootResult = resolveRootForLocator();
|
|
@@ -2106,23 +2160,30 @@
|
|
|
2106
2160
|
const visibleText = pageTextChunks(root, 40, 320);
|
|
2107
2161
|
const combinedText = visibleText.map((chunk) => chunk.text).join("\n");
|
|
2108
2162
|
const scripts = listInlineScripts();
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2163
|
+
const visibleTimestampCandidates = timestampCandidateMatchesFromText(
|
|
2164
|
+
combinedText,
|
|
2165
|
+
Array.isArray(params.patterns) ? params.patterns.map(String) : void 0
|
|
2166
|
+
);
|
|
2167
|
+
const inlineTimestampCandidates = timestampCandidateMatchesFromText(
|
|
2111
2168
|
scripts.map((script) => script.content).join("\n"),
|
|
2112
2169
|
Array.isArray(params.patterns) ? params.patterns.map(String) : void 0
|
|
2113
2170
|
);
|
|
2171
|
+
const previewGlobals = await globalsPreview();
|
|
2172
|
+
const suspiciousGlobals = [...new Set(scripts.flatMap((script) => script.suspectedVars))].slice(0, 50);
|
|
2114
2173
|
return {
|
|
2115
2174
|
url: metadata.url,
|
|
2116
2175
|
title: metadata.title,
|
|
2117
2176
|
html: redactHtmlSnapshot(document.documentElement),
|
|
2118
2177
|
visibleText,
|
|
2119
|
-
visibleTimestamps,
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2178
|
+
visibleTimestamps: visibleTimestampCandidates.map((candidate) => candidate.value),
|
|
2179
|
+
visibleTimestampCandidates,
|
|
2180
|
+
inlineTimestamps: inlineTimestampCandidates.map((candidate) => candidate.value),
|
|
2181
|
+
inlineTimestampCandidates,
|
|
2182
|
+
suspiciousGlobals,
|
|
2183
|
+
globalsPreview: previewGlobals,
|
|
2123
2184
|
scripts: {
|
|
2124
2185
|
inlineCount: scripts.length,
|
|
2125
|
-
suspectedDataVars:
|
|
2186
|
+
suspectedDataVars: suspiciousGlobals
|
|
2126
2187
|
},
|
|
2127
2188
|
storage: storageMetadata(),
|
|
2128
2189
|
cookies: cookieMetadata(),
|
package/dist/manifest.json
CHANGED
package/package.json
CHANGED