Skip to content

Commit eee84fc

Browse files
authored
Add --internal-cookie-store option for Playground CLI (#2323)
## Description Adds a new `--internal-cookie-store` flag in the Playground CLI and a corresponding `internalCookieStore` argument in `RunCLIArgs`. When enabled, all the cookies are stored and served from an internal cookie jar. By default, that option is disabled and the user agent is responsible for handling cookies. ## Motivation Some workflows need Playground to own cookie persistence, e.g. VS Code webview does not store cookies so any Blueprint with autologin enabled results in an infinite redirection loop. ## Testing steps * Start Playground CLI without the flag and confirm that WordPress sends a `set-cookie` header both on the homepage and when logging in. * Restart it with `--internal-cookie-store` and verify no cookies are sent to the browser. Confirm the admin login form still works. cc @bgrgicak @ryanwelcher
1 parent a67cb5b commit eee84fc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/playground/cli/src/run-cli.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ export async function parseOptionsAndRunCLI() {
181181
// Hide this option because we want to replace with a more general log-level flag.
182182
hidden: true,
183183
})
184+
.option('internal-cookie-store', {
185+
describe:
186+
'Enable internal cookie handling. When enabled, Playground will manage cookies internally using ' +
187+
'an HttpCookieStore that persists cookies across requests. When disabled, cookies are handled ' +
188+
'externally (e.g., by a browser in Node.js environments).',
189+
type: 'boolean',
190+
default: false,
191+
})
184192
// TODO: Should we make this a hidden flag?
185193
.option('experimentalMultiWorker', {
186194
describe:
@@ -283,6 +291,7 @@ export interface RunCLIArgs {
283291
followSymlinks?: boolean;
284292
experimentalMultiWorker?: number;
285293
experimentalTrace?: boolean;
294+
internalCookieStore?: boolean;
286295
}
287296

288297
export interface RunCLIServer extends AsyncDisposable {
@@ -638,6 +647,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer> {
638647
processIdSpaceLength,
639648
followSymlinks,
640649
trace,
650+
internalCookieStore: args.internalCookieStore,
641651
});
642652

643653
if (
@@ -728,6 +738,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer> {
728738
processIdSpaceLength,
729739
followSymlinks,
730740
trace,
741+
internalCookieStore: args.internalCookieStore,
731742
});
732743
await additionalPlayground.isReady();
733744

packages/playground/cli/src/worker-thread.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export type PrimaryWorkerBootOptions = {
3232
dataSqlPath?: string;
3333
followSymlinks: boolean;
3434
trace: boolean;
35+
/**
36+
* When true, Playground will not send cookies to the client but will manage
37+
* them internally. This can be useful in environments that can't store cookies,
38+
* e.g. VS Code WebView.
39+
*
40+
* Default: false.
41+
*/
42+
internalCookieStore?: boolean;
3543
};
3644

3745
function mountResources(php: PHP, mounts: Mount[]) {
@@ -110,6 +118,7 @@ export class PlaygroundCliWorker extends PHPWorker {
110118
dataSqlPath,
111119
followSymlinks,
112120
trace,
121+
internalCookieStore,
113122
}: PrimaryWorkerBootOptions) {
114123
if (this.booted) {
115124
throw new Error('Playground already booted');
@@ -175,7 +184,7 @@ export class PlaygroundCliWorker extends PHPWorker {
175184
mountResources(php, mountsBeforeWpInstall);
176185
},
177186
},
178-
cookieStore: false,
187+
cookieStore: internalCookieStore ? undefined : false,
179188
dataSqlPath,
180189
});
181190
this.__internal_setRequestHandler(requestHandler);

0 commit comments

Comments
 (0)