Skip to content

Commit

Permalink
feat: resize container to full page
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed May 26, 2024
1 parent b55f8e0 commit ce38248
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions run-chrome.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,56 @@ function getPort(url) {
app.post("/screenshot", express.json(), async (req, res) => {
try {
// Take a screenshot of the page
const element = await page.$("#ember-testing");
if (!element) {
const emberTesting = await page.$("#ember-testing");
if (!emberTesting) {
throw new Error("No #ember-testing element found");
}

const emberTestingContainer = await page.$("#ember-testing-container");
if (!emberTesting) {
throw new Error("No #ember-testing-container element found");
}

const { name, ...options } = req.body;

// Emulate prefers-reduced-motion: reduce
await page.emulateMediaFeatures([
{ name: "prefers-reduced-motion", value: "reduce" },
]);

// Resize ember-testing to the viewport
await emberTesting.evaluate((element) => {
element.style.width = "auto";
element.style.height = "auto";
element.style.transform = "none";
});

await emberTestingContainer.evaluate((element) => {
element.style.width = "100vw";
element.style.height = "fit-content";
element.style.left = "0";
element.style.top = "0";
});

await argosScreenshot(page, name, {
element,
element: emberTesting,
...options,
});

// Reset the styles
await emberTesting.evaluate((element) => {
element.style.width = "";
element.style.height = "";
element.style.transform = "";
});

await emberTestingContainer.evaluate((element) => {
element.style.width = "";
element.style.height = "";
element.style.left = "";
element.style.top = "";
});

res.sendStatus(200);
} catch (error) {
res.send(error.stack);
Expand Down

0 comments on commit ce38248

Please sign in to comment.