G6: prettyscreenshot --hide keeps a trailing image path as the output path (#1419)

--hide collected every following non-flag argument as a selector, so the
output path was hidden instead of written to. A trailing argument that looks
like a path or ends in .png/.jpg/.jpeg/.webp is now the output path.

Co-authored-by: Jayesh Betala <jayesh.betala7@gmail.com>
This commit is contained in:
garrytanandJayesh Betala committed 2026-10-03 21:12:02 +00:00
1 parent 88b480eaed
commit 5bcc4b5d2c
2 files changed
+21 -2

No files matched your search

+7 -2
View File
@@ -996,13 +996,18 @@ export async function handleWriteCommand(
} else if (args[i] === '--cleanup') {
doCleanup = true;
} else if (args[i] === '--hide' && i + 1 < args.length) {
// Collect all following non-flag args as selectors to hide
// Collect all following non-flag args as selectors to hide. A
// trailing image path is the output path, not a selector (#1419).
const values: string[] = [];
i++;
while (i < args.length && !args[i].startsWith('--')) {
hideSelectors.push(args[i]);
values.push(args[i]);
i++;
}
i--; // Back up since the for loop will increment
const last = values[values.length - 1];
if (!outputPath && values.length > 1 && /^(\/|\.\.?\/|~)|\.(png|jpe?g|webp)$/i.test(last)) outputPath = values.pop();
hideSelectors.push(...values);
} else if (args[i] === '--width' && i + 1 < args.length) {
viewportWidth = parseInt(args[++i], 10);
if (isNaN(viewportWidth)) throw new Error('--width must be a number');
+14
View File
@@ -580,6 +580,20 @@ describe('Interaction', () => {
expect(await handleReadCommand('js', ['document.querySelector("#name").value'], bm)).toBe('');
});
test('prettyscreenshot --hide keeps a trailing image path as the output path (#1419)', async () => {
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
const out = path.join(os.tmpdir(), `pretty-hide-${process.pid}.png`);
fs.rmSync(out, { force: true });
try {
const result = await handleWriteCommand('prettyscreenshot', ['--hide', '#title', '#content', out], bm);
expect(result).toContain(out);
expect(fs.existsSync(out)).toBe(true);
expect(await handleReadCommand('js', ['getComputedStyle(document.querySelector("#content")).display'], bm)).toBe('none');
} finally {
fs.rmSync(out, { force: true });
}
});
test('type -- types text that starts with -- literally; plain text gets no hint', async () => {
await handleWriteCommand('goto', [baseUrl + '/forms.html'], bm);
await handleWriteCommand('click', ['#bio'], bm);