tools: Fix screenshot capturing script to capture the correct area.

As the hotkey might cause the page to be scrolled, thus capturing
the wrong area, I view the message by id instead of using
'#narrow/near' and remove the 'selected_message' class from the
message box to remove the selection highlight on it.

Fixes: #17878
This commit is contained in:
PIG208 2021-03-30 03:33:19 +08:00 committed by Tim Abbott
parent 27d1f5e0e3
commit f42729ab0c
1 changed files with 2 additions and 2 deletions

View File

@ -54,14 +54,14 @@ async function run() {
]);
// Navigate to message and capture screenshot
await page.goto(`http://${host}/#narrow/near/${options.messageId}`);
await page.goto(`http://${host}/#narrow/id/${options.messageId}`);
const messageSelector = `#zfilt${CSS.escape(options.messageId)}`;
await page.waitForSelector(messageSelector);
// remove unread marker and don't select message
const marker = `#zfilt${CSS.escape(options.messageId)} .unread_marker`;
await page.evaluate((sel) => $(sel).remove(), marker);
const messageBox = await page.$(messageSelector);
await page.keyboard.press("KeyK");
await page.evaluate((msg) => $(msg).removeClass("selected_message"), messageSelector);
const messageGroup = (await messageBox.$x(".."))[0];
// Compute screenshot area, with some padding around the message group
const clip = {...(await messageGroup.boundingBox())};