From 60187753fcd4b636c152f3e6d3091cc0c59d00fb Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sat, 1 Mar 2025 12:15:07 +0100 Subject: [PATCH] feat: add `serializeHtml` --- src/html.js | 2 +- src/index.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/html.js b/src/html.js index 50ccbe5..c1b0545 100644 --- a/src/html.js +++ b/src/html.js @@ -216,7 +216,7 @@ module.exports = ({ if (scripts) injectScripts({ $, scripts, type: 'text/javascript' }) if (modules) injectScripts({ $, modules, type: 'module' }) - return rewriteUrls ? rewriteCssUrls({ html: $.html(), url }) : $.html() + return rewriteUrls ? rewriteCssUrls({ html: $.html(), url }) : $ } module.exports.getDate = getDate diff --git a/src/index.js b/src/index.js index acd7e66..a39ef66 100644 --- a/src/index.js +++ b/src/index.js @@ -236,14 +236,14 @@ const getContent = PCancelable.fn( onCancel(() => promise.cancel()) return promise.then(content => { - const html = addHtml({ + const $ = addHtml({ ...content, ...(isFetchMode ? puppeteerOpts : undefined), rewriteUrls, rewriteHtml }) - return { ...content, html } + return { ...content, $ } }) } ) @@ -260,6 +260,7 @@ module.exports = PCancelable.fn( headers, mutoolPath = defaultMutoolPath(), prerender = 'auto', + serializeHtml = $ => ({ html: $.html() }), puppeteerOpts, rewriteUrls = false, rewriteHtml = false @@ -291,9 +292,12 @@ module.exports = PCancelable.fn( onCancel(() => promise.cancel()) - const { mode, ...payload } = await promise + const { mode, $, ...payload } = await promise - return Object.assign(payload, { stats: { mode, timing: duration() } }) + return Object.assign(payload, { + ...serializeHtml($), + stats: { mode, timing: duration() } + }) } )