mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: taking a screenshot with null viewport should be possible (#8680)
Closes #8673
This commit is contained in:
parent
3d780a3f08
commit
2abb9f0c14
@ -785,11 +785,11 @@ export class ElementHandle<
|
|||||||
assert(boundingBox, 'Node is either not visible or not an HTMLElement');
|
assert(boundingBox, 'Node is either not visible or not an HTMLElement');
|
||||||
|
|
||||||
const viewport = this.#page.viewport();
|
const viewport = this.#page.viewport();
|
||||||
assert(viewport);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
boundingBox.width > viewport.width ||
|
viewport &&
|
||||||
boundingBox.height > viewport.height
|
(boundingBox.width > viewport.width ||
|
||||||
|
boundingBox.height > viewport.height)
|
||||||
) {
|
) {
|
||||||
const newViewport = {
|
const newViewport = {
|
||||||
width: Math.max(viewport.width, Math.ceil(boundingBox.width)),
|
width: Math.max(viewport.width, Math.ceil(boundingBox.width)),
|
||||||
@ -826,7 +826,7 @@ export class ElementHandle<
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (needsViewportReset) {
|
if (needsViewportReset && viewport) {
|
||||||
await this.#page.setViewport(viewport);
|
await this.#page.setViewport(viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
setupTestPageAndContextHooks,
|
setupTestPageAndContextHooks,
|
||||||
itFailsFirefox,
|
itFailsFirefox,
|
||||||
itHeadfulOnly,
|
itHeadfulOnly,
|
||||||
|
itChromeOnly,
|
||||||
} from './mocha-utils.js';
|
} from './mocha-utils.js';
|
||||||
|
|
||||||
describe('Screenshots', function () {
|
describe('Screenshots', function () {
|
||||||
@ -214,6 +215,27 @@ describe('Screenshots', function () {
|
|||||||
const screenshot = await elementHandle.screenshot();
|
const screenshot = await elementHandle.screenshot();
|
||||||
expect(screenshot).toBeGolden('screenshot-element-bounding-box.png');
|
expect(screenshot).toBeGolden('screenshot-element-bounding-box.png');
|
||||||
});
|
});
|
||||||
|
itChromeOnly('should work with a null viewport', async () => {
|
||||||
|
const {defaultBrowserOptions, puppeteer, server} = getTestState();
|
||||||
|
|
||||||
|
const browser = await puppeteer.launch({
|
||||||
|
...defaultBrowserOptions,
|
||||||
|
defaultViewport: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
|
await page.evaluate(() => {
|
||||||
|
return window.scrollBy(50, 100);
|
||||||
|
});
|
||||||
|
const elementHandle = (await page.$('.box:nth-of-type(3)'))!;
|
||||||
|
const screenshot = await elementHandle.screenshot();
|
||||||
|
expect(screenshot).toBeTruthy();
|
||||||
|
} finally {
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
it('should take into account padding and border', async () => {
|
it('should take into account padding and border', async () => {
|
||||||
const {page} = getTestState();
|
const {page} = getTestState();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user