Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
puppeteerrequestinterceptor
Advanced tools
Intercept API Requests and return Mocked Data
$ npm install puppeteer-request-intercepter
const puppeteer = require('puppeteer');
const { initFixtureRouter } = require('puppeteer-request-intercepter');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const fixtureRouter = await initFixtureRouter(page, { baseUrl: 'https://news.ycombinator.com' });
fixtureRouter.route('GET', '/y18.gif', 'y18.gif', { contentType: 'image/gif' });
await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle2' });
await page.pdf({ path: 'hn.pdf', format: 'A4' });
await browser.close();
})();
Initialize a new FixtureRouter class.
This class is responsible for configuring and handling Puppeteer requests. Eg. page.on('request')
and page.on('response')
Returns a FixtureRouter object with route
and routeFixture
functions.
Type: object
An instance of the Puppeteer page
object.
Type: object
Default: {}
Decode the keys and values. URL components are decoded with decode-uri-component
.
Type: string
Default: ''
Base Url for relative fixture routes (ex. /api/v1/users
).
const fixtureRouter = await initFixtureRouter(page, { baseUrl: 'https://news.ycombinator.com' });
Type: string
Default: ./puppeteer/fixtures
Base path where the fixture files are located (and will be created if they don't exist).
Add a FixtureRoute
to the FixtureRouter
instance.
Type: string
The HttpMethod to match:
Type: string
The full or relative Url to match.
Comparison is done using startsWith()
and the order in which FixtureRoute
's are added matters. The first one found will be used.
Put the most specific match first. Ex:
fixtureRouter.route('GET', '/api/v1/users/bill', 'bill.json');
fixtureRouter.route('GET', '/api/v1/users', 'all-users.json');
Type: string
Relative path of the fixture file to use (or create).
Type: object
Default: {}
FixtureRouteOptions
to use for the response.
Type: string
Default: application/json
Specifies the Content-Type response header.
Type: number
Specifies the response status code.
Add a FixtureRoute
to the FixtureRouter
instance.
Options are the same as fixtureRouter.route()
except it accepts an object of parameters instead of individual ones.
Returns the first FixtureRoute
that matches the provided method
and url
. If there are no matches it returns undefined
.
Type: string
The HttpMethod to match.
Type: string
The full or relative Url to match.
If it's a relative Url, the configured baseUrl
will be used.
Convenience method for creating FixtureRoute
's.
Same API as fixtureRouter.route
.
Useful when using BackstopJS
with a custom scenarios.fixtures
array.
import { Scenario } from 'backstopjs';
import { Page } from 'puppeteer';
import { initFixtureRouter } from 'puppeteer-request-intercepter';
// tslint:disable-next-line: export-name
export = async (page: Page, scenario: Scenario, vp) => {
// Configure fixtures:
if (scenario.fixtures) {
const fixtureRouter = await initFixtureRouter(page, {
baseUrl: `http://localhost:8080`,
fixtureBasePath: 'backstop_data/engine_scripts/fixtures',
});
scenario.fixtures.forEach((fixture) => {
fixtureRouter.routeFixture(fixture);
});
}
};
import { Config, Scenario } from 'backstopjs';
import { Page } from 'puppeteer';
import { createFixture, FixtureRoute } from 'puppeteer-request-intercepter';
const globalFixtures: FixtureRoute[] = [
createFixture('GET', '/api/v1/alerts', 'alerts.json'),
];
const config: Config = {
id: 'MyProject',
viewports: [
{
label: 'phone',
width: 320,
height: 1200,
},
{
label: 'tablet',
width: 1024,
height: 768,
},
{
label: 'desktop',
width: 1200,
height: 900,
},
],
paths: {
bitmaps_reference: 'backstop_data/bitmaps_reference',
bitmaps_test: 'backstop_data/bitmaps_test',
engine_scripts: 'backstop_data/dist/engine_scripts',
html_report: 'backstop_data/html_report',
ci_report: 'backstop_data/ci_report',
},
report: ['browser'],
engine: 'puppeteer',
engineOptions: {
args: ['--no-sandbox'],
},
asyncCaptureLimit: 5,
asyncCompareLimit: 50,
debug: false,
debugWindow: false,
onBeforeScript: 'onBefore.js',
onReadyScript: 'onReady.js',
scenarios: [
{
label: 'dashboards',
url: url('/dashboards'),
fixtures: [
...globalFixtures,
createFixture('GET', '/api/v1/dashboards', 'dashboards.json')
],
},
],
};
export = config;
FAQs
security holding package
The npm package puppeteerrequestinterceptor receives a total of 0 weekly downloads. As such, puppeteerrequestinterceptor popularity was classified as not popular.
We found that puppeteerrequestinterceptor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.