Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function benchRequestParsing({
requests,
}: {
requests: Array<{ url: string; frameUrl: string; cpt: string }>;
}) {
for (let i = 0; i < requests.length; i += 1) {
const { url, frameUrl, cpt } = requests[i];
Request.fromRawDetails({
sourceUrl: frameUrl,
// @ts-ignore
type: cpt,
url,
});
}
}
export function fromElectronDetails({
id,
url,
resourceType,
referrer,
webContentsId,
}: Electron.OnHeadersReceivedListenerDetails | Electron.OnBeforeRequestListenerDetails): Request {
return Request.fromRawDetails({
requestId: `${id}`,
sourceUrl: referrer,
tabId: webContentsId,
type: (resourceType || 'other') as ElectronRequestType,
url,
});
}
export function fromPuppeteerDetails(details: puppeteer.Request): Request {
const frame = details.frame();
const sourceUrl = frame !== null ? frame.url() : undefined;
return Request.fromRawDetails({
requestId: `${details.resourceType()} ${details.url()} ${sourceUrl}`,
sourceUrl,
type: details.resourceType(),
url: details.url(),
});
}
export function fromWebRequestDetails(
details: WebRequestBeforeRequestDetails | WebRequestHeadersReceivedDetails,
): Request {
return Request.fromRawDetails({
requestId: details.requestId,
sourceUrl: details.initiator || details.originUrl || details.documentUrl,
tabId: details.tabId,
type: details.type,
url: details.url,
});
}
match({ url, frameUrl, type }) {
return this.engine.match(Request.fromRawDetails({
url,
sourceUrl: frameUrl,
type,
})).match;
}
};