Skip to content

Commit b6a72f5

Browse files
committed
fix(mitm): bubble proxy errors properly to client
chore(all): eslint rule to disallow async without await fix for #98
1 parent 20ba30c commit b6a72f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+674
-515
lines changed

.eslintrc.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
},
5050
overrides: [
5151
{
52-
files: ['*client/**/*.ts', '*interfaces/**/*.ts', 'commons/**/*.ts'],
52+
files: ['*client/**/*.ts', '*interfaces/**/*.ts', 'commons/**/*.ts', 'mitm*/**/*.ts'],
5353
rules: {
5454
'@typescript-eslint/explicit-function-return-type': [
5555
'error',
@@ -63,6 +63,12 @@ module.exports = {
6363
'no-console': 'off',
6464
},
6565
},
66+
{
67+
files: 'emulate-browsers/**/*.ts',
68+
rules: {
69+
'require-await': 'off', // Turn off while waiting
70+
},
71+
},
6672
{
6773
files: [
6874
'**/injected-scripts/**/*.js',
@@ -75,6 +81,7 @@ module.exports = {
7581
'prefer-rest-params': 'off',
7682
'max-classes-per-file': 'off',
7783
'func-names': 'off',
84+
'@typescript-eslint/no-unused-vars': 'off',
7885
},
7986
},
8087
{
@@ -91,6 +98,7 @@ module.exports = {
9198
rules: {
9299
'promise/valid-params': 'off',
93100
'@typescript-eslint/explicit-function-return-type': 'off',
101+
'require-await': 'off',
94102
},
95103
},
96104
{
@@ -164,6 +172,8 @@ module.exports = {
164172
'class-methods-use-this': 'off',
165173
'consistent-return': ['off', { treatUndefinedAsUnspecified: true }],
166174
'spaced-comment': ['error', 'always', { markers: ['/////'] }],
175+
'require-await': 'error',
176+
'jest/no-conditional-expect': 'off',
167177
'@typescript-eslint/no-implied-eval': 'off', // false positives for setTimeout with bind fn
168178
'@typescript-eslint/no-explicit-any': 'off',
169179
'@typescript-eslint/no-use-before-define': 'off',
@@ -174,6 +184,10 @@ module.exports = {
174184
'@typescript-eslint/no-empty-interface': 'off',
175185
'@typescript-eslint/no-namespace': 'off',
176186
'@typescript-eslint/ordered-imports': 'off',
187+
'@typescript-eslint/no-shadow': [
188+
'error',
189+
{ ignoreTypeValueShadow: true, ignoreFunctionTypeParameterNameValueShadow: true },
190+
],
177191
'@typescript-eslint/object-literal-shorthand': 'off',
178192
'@typescript-eslint/object-shorthand-properties-first': 'off',
179193
'@typescript-eslint/no-var-requires': 'off',

client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function SecretAgentClientGenerator(
216216

217217
/////// METHODS THAT DELEGATE TO ACTIVE TAB //////////////////////////////////////////////////////////////////////////
218218

219-
public async goto(href: string): Promise<Resource> {
219+
public goto(href: string): Promise<Resource> {
220220
return this.activeTab.goto(href);
221221
}
222222

client/lib/CoreCommandQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class CoreCommandQueue {
2121
}
2222
}
2323

24-
public async run<T>(command: string, ...args: any[]): Promise<T> {
24+
public run<T>(command: string, ...args: any[]): Promise<T> {
2525
const { resolve, reject, promise } = createPromise<T>();
2626
this.items.push({
2727
resolve,

client/lib/CoreTab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class CoreTab {
5151
}
5252
}
5353

54-
public async getResourceProperty<T = any>(id: number, propertyPath: string): Promise<T> {
54+
public getResourceProperty<T = any>(id: number, propertyPath: string): Promise<T> {
5555
return this.commandQueue.run('getResourceProperty', id, propertyPath);
5656
}
5757

client/lib/Request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const { getState, setState } = StateMachine<FetchRequest, IState>();
1616

1717
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1818
export default function RequestGenerator(coreTab: Promise<CoreTab>) {
19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1920
return class Request extends FetchRequest {
2021
constructor(input: IRequestInfo, init?: IRequestInit) {
2122
super(input, init);

client/lib/SetupAwaitedHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function construct<TClass>(self: AwaitedHandler<TClass>): TClass {
8787
throw new NotImplementedError(`${self.className} constructor not implemented`);
8888
}
8989

90-
async function execJsPath<TClass, T>(
90+
function execJsPath<TClass, T>(
9191
self: AwaitedHandler<TClass>,
9292
coreTab: CoreTab,
9393
instance: TClass,

client/lib/Tab.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default class Tab extends AwaitedEventTarget<IEventType, IState> {
141141
await coreTab.waitForLoad(status);
142142
}
143143

144-
public async waitForResource(
144+
public waitForResource(
145145
filter: IWaitForResourceFilter,
146146
options?: IWaitForResourceOptions,
147147
): Promise<(Resource | WebsocketResource)[]> {
@@ -172,15 +172,15 @@ export default class Tab extends AwaitedEventTarget<IEventType, IState> {
172172
await coreTab.waitForWebSocket(url);
173173
}
174174

175-
public async focus(): Promise<void> {
175+
public focus(): Promise<void> {
176176
const { secretAgent, coreTab } = getState(this);
177177
agentState.setState(secretAgent, {
178178
activeTab: this,
179179
});
180180
return coreTab.then(x => x.focusTab());
181181
}
182182

183-
public async close(): Promise<void> {
183+
public close(): Promise<void> {
184184
const { secretAgent, coreTab } = getState(this);
185185
const { tabs } = agentState.getState(secretAgent);
186186
const updatedTabs = tabs.filter(x => x !== this);

commons/decodeBuffer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import zlib from 'zlib';
22
import { createPromise } from './utils';
33

4-
export default async function decodeBuffer(buffer: Buffer, encoding: string): Promise<Buffer> {
4+
export default function decodeBuffer(buffer: Buffer, encoding: string): Promise<Buffer> {
55
if (!buffer) return null;
6-
if (!encoding) return buffer;
6+
if (!encoding) return Promise.resolve(buffer);
77

88
const promise = createPromise<Buffer>();
99
const handler = (error, result): void => {

commons/eventUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class TypedEventEmitter<T> extends EventEmitter implements ITypedEventEmi
8686
this.eventsToLog = new Set<string | symbol>(events);
8787
}
8888

89-
public async waitOn<K extends keyof T & (string | symbol)>(
89+
public waitOn<K extends keyof T & (string | symbol)>(
9090
eventType: K,
9191
listenerFn?: (this: this, event?: T[K]) => boolean,
9292
timeoutMillis = 30e3,

core-interfaces/INetworkInterceptorDelegate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default interface INetworkInterceptorDelegate {
1111
};
1212
dns?: {
1313
dnsOverTlsConnection: ConnectionOptions;
14+
useUpstreamProxy?: boolean;
1415
};
1516
connections?: {
1617
socketsPerOrigin: number;

0 commit comments

Comments
 (0)