fix(proxy): fix requests with proxies (#1408)

This commit is contained in:
Mark Dietzer
2020-12-15 14:08:38 -08:00
committed by GitHub
parent ecdb7a058d
commit f65df4ce56
5 changed files with 181 additions and 170 deletions
+9 -3
View File
@@ -14,7 +14,8 @@ import {
delay,
getRandomUserAgent,
getSleepTime,
isStatusCodeInRange
isStatusCodeInRange,
noop
} from '../util';
import {disableBlockerInPage, enableBlockerInPage} from '../adblocker';
import {config} from '../config';
@@ -23,7 +24,7 @@ import {filterStoreLink} from './filter';
import open from 'open';
import {processBackoffDelay} from './model/helpers/backoff';
import {sendNotification} from '../notification';
import useProxy from 'puppeteer-page-proxy';
import useProxy from '@doridian/puppeteer-page-proxy';
const inStock: Record<string, boolean> = {};
@@ -75,7 +76,7 @@ async function handleProxy(request: Request, proxy?: string) {
try {
await useProxy(request, proxy);
} catch (error: unknown) {
logger.error(error);
logger.error('handleProxy', error);
try {
await request.abort();
} catch {}
@@ -203,6 +204,11 @@ async function lookup(browser: Browser, store: Store) {
return onProxyFunc;
}
// Give dummy setRequestInterception to avoid AdBlock from messing with it
if (prop === 'setRequestInterception') {
return noop;
}
return Reflect.get(target, prop, receiver);
}
});
+5 -1
View File
@@ -18,6 +18,10 @@ export async function delay(ms: number) {
});
}
export function noop() {
// Do nothing
}
export function isStatusCodeInRange(
statusCode: number,
range: StatusCodeRangeArray
@@ -66,7 +70,7 @@ export async function usingPage<T>(
try {
await closePage(page);
} catch (error: unknown) {
logger.error(error);
logger.error('usingPage', error);
}
}
}