Skip to content

Commit

Permalink
fix(adblock): proxy another function to produce less errors (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doridian committed Dec 13, 2020
1 parent 38630d4 commit eb70076
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/store/lookup.ts
@@ -1,4 +1,11 @@
import {Browser, Page, PageEventObj, Request, Response} from 'puppeteer';
import {
Browser,
Page,
PageEventObj,
Request,
RespondOptions,
Response
} from 'puppeteer';
import {Link, Store, getStores} from './model';
import {Print, logger} from '../logger';
import {Selector, getPrice, pageIncludesLabels} from './includes-labels';
Expand Down Expand Up @@ -95,6 +102,14 @@ async function handleAdBlock(request: Request, adBlockRequestHandler: any) {
resolve(true);
};

const respondFunc = async (response: RespondOptions) => {
try {
await request.respond(response);
} catch {}

resolve(true);
};

const requestProxy = new Proxy(request, {
get(target, prop, receiver) {
if (prop === 'continue') {
Expand All @@ -105,9 +120,14 @@ async function handleAdBlock(request: Request, adBlockRequestHandler: any) {
return abortFunc;
}

if (prop === 'respond') {
return respondFunc;
}

return Reflect.get(target, prop, receiver);
}
});

adBlockRequestHandler(requestProxy);
});
}
Expand Down Expand Up @@ -220,7 +240,6 @@ async function lookup(browser: Browser, store: Store) {
);
const client = await page.target().createCDPSession();
await client.send('Network.clearBrowserCookies');
// Await client.send('Network.clearBrowserCache');
}

if (pageProxy) {
Expand Down

0 comments on commit eb70076

Please sign in to comment.