Skip to content

Commit bdf7960

Browse files
committed
WIP
1 parent a3702cd commit bdf7960

File tree

6 files changed

+1026
-820
lines changed

6 files changed

+1026
-820
lines changed

Extension/src/background/javascript-instrument.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class JavascriptInstrument {
140140
matchAboutBlank: true,
141141
});
142142
}
143-
const entryScript = (this.legacy) ? "/content.js" : "/stealth.js";
143+
const entryScript = this.legacy ? "/content.js" : "/stealth.js";
144144
return browser.contentScripts.register({
145145
js: [{ file: entryScript }],
146146
matches: ["<all_urls>"],

Extension/src/feature.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function main() {
2020
navigation_instrument: true,
2121
cookie_instrument: true,
2222
js_instrument: true,
23-
stealth_js_instrument:false,
23+
stealth_js_instrument: false,
2424
cleaned_js_instrument_settings: [
2525
{
2626
object: `window.CanvasRenderingContext2D.prototype`,
@@ -72,16 +72,20 @@ async function main() {
7272
const cookieInstrument = new CookieInstrument(loggingDB);
7373
cookieInstrument.run(config.browser_id);
7474
}
75-
if (config['stealth_js_instrument']) {
75+
if (config.stealth_js_instrument) {
7676
loggingDB.logDebug("Stealth JavaScript Instrumentation enabled");
77-
let stealthJSInstrument = new JavascriptInstrument(loggingDB, false);
78-
stealthJSInstrument.run(config['browser_id']);
77+
const stealthJSInstrument = new JavascriptInstrument(loggingDB, false);
78+
stealthJSInstrument.run(config.browser_id);
7979
await stealthJSInstrument.registerContentScript();
80-
} if (config['js_instrument']) {
80+
}
81+
if (config.js_instrument) {
8182
loggingDB.logDebug("Javascript instrumentation enabled");
82-
let jsInstrument = new JavascriptInstrument(loggingDB, true);
83-
jsInstrument.run(config['browser_id']);
84-
await jsInstrument.registerContentScript(config['testing'], config['cleaned_js_instrument_settings']);
83+
const jsInstrument = new JavascriptInstrument(loggingDB, true);
84+
jsInstrument.run(config.browser_id);
85+
await jsInstrument.registerContentScript(
86+
config.testing,
87+
config.cleaned_js_instrument_settings,
88+
);
8589
}
8690

8791
if (config.http_instrument) {

Extension/src/stealth/error.ts

+49-47
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
22
* Functionality to generate error objects
33
*/
4-
function generateErrorObject(err, context){
4+
function generateErrorObject(err, context) {
55
// TODO: Pass context
6-
context = (context !== undefined) ? context : window;
7-
const cleaned = cleanErrorStack(err.stack)
6+
context = context !== undefined ? context : window;
7+
const cleaned = cleanErrorStack(err.stack);
88
const stack = splitStack(cleaned);
99
const lineInfo = getLineInfo(stack);
1010
const fileName = getFileName(stack);
11-
let fakeError;
12-
try{
11+
let fakeError: { lineNumber: any; columnNumber: any };
12+
try {
1313
// fake type, message, filename, column and line
14-
const propertyName = "stack";
14+
// const propertyName = "stack";
1515
fakeError = new context.wrappedJSObject[err.name](err.message, fileName);
1616
fakeError.lineNumber = lineInfo.lineNumber;
1717
fakeError.columnNumber = lineInfo.columnNumber;
18-
}catch(error){
18+
} catch (error) {
1919
console.log("ERROR creation failed. Error was:" + error);
2020
}
2121
return fakeError;
@@ -26,10 +26,10 @@ function generateErrorObject(err, context){
2626
*/
2727
function cleanErrorStack(stack) {
2828
const extensionID = browser.runtime.getURL("");
29-
const lines = (typeof(stack) !== "string") ? stack : splitStack(stack);
30-
lines.forEach(line =>{
31-
if (line.includes(extensionID)){
32-
stack = stack.replace(line+"\n","");
29+
const lines = typeof stack !== "string" ? stack : splitStack(stack);
30+
lines.forEach((line) => {
31+
if (line.includes(extensionID)) {
32+
stack = stack.replace(line + "\n", "");
3333
}
3434
});
3535
return stack;
@@ -40,9 +40,9 @@ function cleanErrorStack(stack) {
4040
*/
4141
function getBeginOfScriptCalls(stack) {
4242
const extensionID = browser.runtime.getURL("");
43-
const lines = (typeof(stack) !== "string") ? stack : splitStack(stack);
44-
for (let i=0; i<lines.length; i++){
45-
if (!lines[i].includes(extensionID)){
43+
const lines = typeof stack !== "string" ? stack : splitStack(stack);
44+
for (let i = 0; i < lines.length; i++) {
45+
if (!lines[i].includes(extensionID)) {
4646
return i;
4747
}
4848
}
@@ -52,8 +52,10 @@ function getBeginOfScriptCalls(stack) {
5252
/*
5353
* Get the stack as array
5454
*/
55-
function splitStack(stack){
56-
return stack.split('\n').map(function (line) { return line.trim(); });
55+
function splitStack(stack) {
56+
return stack.split("\n").map(function (line) {
57+
return line.trim();
58+
});
5759
}
5860

5961
/*
@@ -64,15 +66,17 @@ function getLineInfo(stack) {
6466
const firstLine = stack[0];
6567
const matches = [...firstLine.matchAll(":")];
6668
const column = firstLine.slice(
67-
matches[matches.length-1].index + 1,
68-
firstLine.length);
69+
matches[matches.length - 1].index + 1,
70+
firstLine.length,
71+
);
6972
const line = firstLine.slice(
70-
matches[matches.length-2].index + 1,
71-
matches[matches.length-1].index);
73+
matches[matches.length - 2].index + 1,
74+
matches[matches.length - 1].index,
75+
);
7276
return {
73-
"lineNumber": line,
74-
"columnNumber": column
75-
}
77+
lineNumber: line,
78+
columnNumber: column,
79+
};
7680
}
7781

7882
/*
@@ -84,35 +88,34 @@ function getFileName(stack) {
8488
const matches_at = [...firstLine.matchAll("@")];
8589
const matches_colon = [...firstLine.matchAll(":")];
8690
return firstLine.slice(
87-
matches_at[matches_at.length-1].index + 1,
88-
matches_colon[matches_colon.length-2].index
91+
matches_at[matches_at.length - 1].index + 1,
92+
matches_colon[matches_colon.length - 2].index,
8993
);
9094
}
9195

92-
function getOriginFromStackTrace(err, includeStack){
93-
console.log(err.stack);
96+
// function getOriginFromStackTrace(err, includeStack){
97+
// console.log(err.stack);
9498

95-
const stack = splitStack(err.stack);
96-
const lineInfo = getLineInfo(stack);
97-
const fileName = getFileName(stack);
98-
99-
const callSite = stack[1];
100-
const callSiteParts = callSite.split("@");
101-
const funcName = callSiteParts[0] || "";
102-
const items = rsplit(callSiteParts[1], ":", 2);
103-
const scriptFileName = items[items.length - 3] || "";
99+
// const stack = splitStack(err.stack);
100+
// const lineInfo = getLineInfo(stack);
101+
// const fileName = getFileName(stack);
104102

105-
const callContext = {
106-
scriptUrl,
107-
scriptLine: lineInfo.lineNumber,
108-
scriptCol: lineInfo.columnNumber,
109-
funcName,
110-
scriptLocEval,
111-
callStack: includeStack ? trace.slice(3).join("\n").trim() : "",
112-
};
103+
// const callSite = stack[1];
104+
// const callSiteParts = callSite.split("@");
105+
// const funcName = callSiteParts[0] || "";
106+
// const items = rsplit(callSiteParts[1], ":", 2);
107+
// const scriptFileName = items[items.length - 3] || "";
113108

114-
}
109+
// const callContext = {
110+
// scriptUrl,
111+
// scriptLine: lineInfo.lineNumber,
112+
// scriptCol: lineInfo.columnNumber,
113+
// funcName,
114+
// scriptLocEval,
115+
// callStack: includeStack ? trace.slice(3).join("\n").trim() : "",
116+
// };
115117

118+
// }
116119

117120
// Helper to get originating script urls
118121
// Legacy code
@@ -128,5 +131,4 @@ function getStackTrace() {
128131
return stack;
129132
}
130133

131-
132-
export { generateErrorObject, getBeginOfScriptCalls, getStackTrace };
134+
export { generateErrorObject, getBeginOfScriptCalls, getStackTrace };

0 commit comments

Comments
 (0)