diff --git a/src/local.js b/src/local.js index 33494e7..93c17b7 100644 --- a/src/local.js +++ b/src/local.js @@ -127,6 +127,78 @@ async function decodeProxyResponseBuffer(responseBuffer, proxyRes) { return responseBuffer.toString('utf8'); } +// window.pageSchemas is set in the first large but before later bundles (and before the small +// `if (window.campaign)` script). Edge strips +// before HTML is sent, and injecting before
', + ``, + '', + 'runs too late (React has +// already read pageSchemas). +const AFTER_CAMPAIGN_BOOTSTRAP = + /(<\/script>)(\s* but before later bundles (and before the small - // `if (window.campaign)` script). Edge strips - // before HTML is sent, and injecting before runs too late (React - // already read pageSchemas). - if (pageOverride) { - const afterCampaignBootstrap = - /(<\/script>)(\s* ` - ); - } - ), + ); + }, }) ); diff --git a/tests/local-proxy.test.js b/tests/local-proxy.test.js new file mode 100644 index 0000000..453c63f --- /dev/null +++ b/tests/local-proxy.test.js @@ -0,0 +1,148 @@ +import { describe, test } from 'vitest'; +import assert from 'node:assert/strict'; +import http from 'node:http'; +import vm from 'node:vm'; + +import express from 'express'; + +import { createCampaignProxy, injectPageOverride } from '../src/local.js'; +import { buildPageOverrideScript } from '../src/actions/pages.js'; + +/** Campaign HTML shaped like the real one: pageSchemas bootstrap, then the small window.campaign script. */ +function campaignHtml(bodyCopy = 'hello') { + return [ + '