Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/phoenix/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ async function _capturePageBinary(rectOrNodeOrSelector) {
}
const maxWidth = Math.ceil(window.innerWidth * boundsScale);
const maxHeight = Math.ceil(window.innerHeight * boundsScale);
if (rect.x + rect.width > maxWidth) {
throw new Error("rect x + width exceeds window innerWidth");
}
if (rect.y + rect.height > maxHeight) {
throw new Error("rect y + height exceeds window innerHeight");
if (rect.x >= maxWidth || rect.y >= maxHeight) {
throw new Error("rect origin leaves no capturable area");
}

rect.width = Math.min(rect.width, maxWidth - rect.x);
rect.height = Math.min(rect.height, maxHeight - rect.y);
}
if (window.__TAURI__) {
const bytes = await window.__TAURI__.invoke('capture_page', { rect });
Expand Down
20 changes: 13 additions & 7 deletions test/spec/Native-platform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,22 @@ define(function (require, exports, module) {
).toBeRejectedWithError("rect width and height must be greater than 0");
});

it("Should throw when rect exceeds window width bounds", async function () {
await expectAsync(
Phoenix.app.screenShotBinary({x: 0, y: 0, width: 999999, height: 100})
).toBeRejectedWithError("rect x + width exceeds window innerWidth");
it("Should clamp an oversize width rect and return a valid PNG", async function () {
const bytes = await Phoenix.app.screenShotBinary({x: 0, y: 0, width: 999999, height: 100});
expect(bytes instanceof Uint8Array).toBeTrue();
expect(isPNG(bytes)).withContext("Result should be valid PNG data").toBeTrue();
});

it("Should clamp an oversize height rect and return a valid PNG", async function () {
const bytes = await Phoenix.app.screenShotBinary({x: 0, y: 0, width: 100, height: 999999});
expect(bytes instanceof Uint8Array).toBeTrue();
expect(isPNG(bytes)).withContext("Result should be valid PNG data").toBeTrue();
});

it("Should throw when rect exceeds window height bounds", async function () {
it("Should throw when rect origin leaves no capturable area", async function () {
await expectAsync(
Phoenix.app.screenShotBinary({x: 0, y: 0, width: 100, height: 999999})
).toBeRejectedWithError("rect y + height exceeds window innerHeight");
Phoenix.app.screenShotBinary({x: 999999, y: 0, width: 100, height: 100})
).toBeRejectedWithError("rect origin leaves no capturable area");
});

it("Should capture a screenshot of a DOM element", async function () {
Expand Down
Loading