Skip to content

Commit

Permalink
Merge pull request #411 from GSA/lc/update-puppeteer
Browse files Browse the repository at this point in the history
Update Puppeteer to v23.8.0, Configure Cache Directory, and Enhance Consumer Instances
  • Loading branch information
luke-at-flexion authored Nov 22, 2024
2 parents e65eb8a + 297186e commit 4035888
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ venv/

# data for security scan
/security-data

# Puppeteer cache
.cache/
9 changes: 9 additions & 0 deletions .puppeteerrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {join} = require('path');

/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};
10 changes: 7 additions & 3 deletions libs/browser/src/puppeteer-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ export const createPuppeteerPool = (
// Create a generic pool instance.
const pool = genericPool.createPool<puppeteer.Browser>(
{
create: () => {
create: async () => {
logger.info({ msg: 'Creating browser...' });
return puppeteer.launch(options.puppeteerArgs).then((browser) => {
try {
const browser = await puppeteer.launch(options.puppeteerArgs);
useCounts.set(browser, 0);
validators.set(browser, createValidator(browser, logger));
return browser;
});
} catch (error) {
logger.error({ error }, `Error creating browser: ${error.message}`);
throw error;
}
},
destroy: async (browser) => {
logger.info({ msg: 'Destroying browser...' });
Expand Down
3 changes: 3 additions & 0 deletions libs/core-scanner/src/core-scanner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export class CoreScannerService
scanLogger.warn(`Scan filtering enabled! Only '${input.scan}' will be executed. This should never be used in production!`);
}

scanLogger.info('Calling browser service to start scan...');
return await this.browserService.useBrowser(async (browser) => {
const result = this.initResultObject(input);

// Iterate over the Page enum and run the scan for each page vis this.runPage()
scanLogger.info('Running scans for all pages...');
for (const page in Page) {
scanLogger.info(`Running scan for page '${Page[page]}'...`);
if (Object.prototype.hasOwnProperty.call(Page, page)) {
const pageName = Page[page];
result[pageName] = await this.runPage(pageName, input, scanLogger, browser);
Expand Down
4 changes: 2 additions & 2 deletions vars-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ producer_disk: 5G
scan_schedule: '0 0 * * *'
snapshot_schedule: '0 8 * * Sun'

consumer_instances: 12
consumer_memory: 650MB
consumer_instances: 10
consumer_memory: 1GB
consumer_disk: 5G

0 comments on commit 4035888

Please sign in to comment.