Skip to content

Commit

Permalink
Small performance and other corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed May 13, 2024
1 parent eea8edf commit 067e026
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 264 deletions.
4 changes: 2 additions & 2 deletions dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ export async function newPage() {
*/
export async function clearPage(page, hardReset = false) {
try {
if (hardReset) {
// Navigate to about:blank
await page.goto('about:blank', { waitUntil: 'domcontentloaded' });

// Set the content and and scripts again
await setPageContent(page);
} else {
// Clear body content
await page.evaluate(() => {
document.body.innerHTML =
'<div id="chart-container"><div id="container"></div></div>';
});
if (!page.isClosed()) {
if (hardReset) {
// Navigate to about:blank
await page.goto('about:blank', { waitUntil: 'domcontentloaded' });

// Set the content and and scripts again
await setPageContent(page);
} else {
// Clear body content
await page.evaluate(() => {
document.body.innerHTML =
'<div id="chart-container"><div id="container"></div></div>';
});
}
}
} catch (error) {
logWithStack(
Expand Down
12 changes: 8 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
setLogLevel,
enableFileLogging
} from './logger.js';
import { initPool } from './pool.js';
import { initPool, killPool } from './pool.js';
import { shutdownCleanUp } from './resource_release.js';
import server, { startServer } from './server/server.js';
import { printLogo, printUsage } from './utils.js';
Expand Down Expand Up @@ -122,16 +122,20 @@ export default {
batchExport,
startExport,

// Other
setOptions,
shutdownCleanUp,
// Pool
initPool,
killPool,

// Logs
log,
logWithStack,
setLogLevel,
enableFileLogging,

// Other
setOptions,
shutdownCleanUp,

// Utils
mapToNewConfig,
manualConfig,
Expand Down
10 changes: 1 addition & 9 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,7 @@ const factory = {
);
return false;
}

// Clear page
try {
const { other } = getOptions();
await clearPage(workerHandle.page, other.hardResetPage);
return true;
} catch {
return false;
}
return true;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import DOMPurify from 'dompurify';
export function sanitize(input) {
const window = new JSDOM('').window;
const purify = DOMPurify(window);
return purify.sanitize(input);
return purify.sanitize(input, { ADD_TAGS: ['foreignObject'] });
}

export default sanitize;
2 changes: 1 addition & 1 deletion lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const defaultConfig = {
'--disable-dev-shm-usage',
'--disable-domain-reliability',
'--disable-extensions',
'--disable-features=CalculateNativeWinOcclusion,InterestFeedContentSuggestions,MediaRouter,Translate,WebOTP',
'--disable-features=CalculateNativeWinOcclusion,InterestFeedContentSuggestions,WebOTP',
'--disable-hang-monitor',
'--disable-ipc-flooding-protection',
'--disable-logging',
Expand Down
Loading

0 comments on commit 067e026

Please sign in to comment.