browser(firefox): make dpr emulation optional, take screenshots at 1x (#5555)

- deviceScaleFactor is now optional, so we can use host machine's dpr.
- Screenshots are not scaled up by dpr.
- Removed unused methods.
This commit is contained in:
Dmitry Gozman 2021-04-01 14:51:02 -07:00 committed by GitHub
parent 2290d8f81f
commit 66541552d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 41 deletions

View file

@ -1,2 +1,2 @@
1241
Changed: joel.einbinder@gmail.com Thu Apr 1 11:26:01 PDT 2021
1242
Changed: dgozman@gmail.com Thu Apr 1 13:10:41 PDT 2021

View file

@ -206,7 +206,6 @@ class PageAgent {
dispatchMouseEvent: this._dispatchMouseEvent.bind(this),
dispatchTouchEvent: this._dispatchTouchEvent.bind(this),
dispatchTapEvent: this._dispatchTapEvent.bind(this),
getBoundingBox: this._getBoundingBox.bind(this),
getContentQuads: this._getContentQuads.bind(this),
getFullAXTree: this._getFullAXTree.bind(this),
goBack: this._goBack.bind(this),
@ -622,31 +621,13 @@ class PageAgent {
return {x: x1, y: y1, width: x2 - x1, height: y2 - y1};
}
async _getBoundingBox({frameId, objectId}) {
const frame = this._frameTree.frame(frameId);
if (!frame)
throw new Error('Failed to find frame with id = ' + frameId);
const unsafeObject = this._frameData.get(frame).unsafeObject(objectId);
const box = this._getNodeBoundingBox(unsafeObject);
if (!box)
return {boundingBox: null};
return {boundingBox: {x: box.x + frame.domWindow().scrollX, y: box.y + frame.domWindow().scrollY, width: box.width, height: box.height}};
}
async _screenshot({mimeType, fullPage, clip}) {
async _screenshot({mimeType, clip, omitDeviceScaleFactor}) {
const content = this._messageManager.content;
if (clip) {
const data = takeScreenshot(content, clip.x, clip.y, clip.width, clip.height, mimeType);
const data = takeScreenshot(content, clip.x, clip.y, clip.width, clip.height, mimeType, omitDeviceScaleFactor);
return {data};
}
if (fullPage) {
const rect = content.document.documentElement.getBoundingClientRect();
const width = content.innerWidth + content.scrollMaxX - content.scrollMinX;
const height = content.innerHeight + content.scrollMaxY - content.scrollMinY;
const data = takeScreenshot(content, 0, 0, width, height, mimeType);
return {data};
}
const data = takeScreenshot(content, content.scrollX, content.scrollY, content.innerWidth, content.innerHeight, mimeType);
const data = takeScreenshot(content, content.scrollX, content.scrollY, content.innerWidth, content.innerHeight, mimeType, omitDeviceScaleFactor);
return {data};
}
@ -1021,10 +1002,10 @@ class PageAgent {
}
}
function takeScreenshot(win, left, top, width, height, mimeType) {
function takeScreenshot(win, left, top, width, height, mimeType, omitDeviceScaleFactor) {
const MAX_SKIA_DIMENSIONS = 32767;
const scale = win.devicePixelRatio;
const scale = omitDeviceScaleFactor ? 1 : win.devicePixelRatio;
const canvasWidth = width * scale;
const canvasHeight = height * scale;

View file

@ -299,10 +299,6 @@ class PageHandler {
return await this._contentPage.send('screenshot', options);
}
async ['Page.getBoundingBox'](options) {
return await this._contentPage.send('getBoundingBox', options);
}
async ['Page.getContentQuads'](options) {
return await this._contentPage.send('getContentQuads', options);
}

View file

@ -71,7 +71,7 @@ pageTypes.Size = {
pageTypes.Viewport = {
viewportSize: pageTypes.Size,
deviceScaleFactor: t.Number,
deviceScaleFactor: t.Optional(t.Number),
};
pageTypes.DOMQuad = {
@ -801,15 +801,6 @@ const Page = {
frameId: t.String,
},
},
'getBoundingBox': {
params: {
frameId: t.String,
objectId: t.String,
},
returns: {
boundingBox: t.Nullable(pageTypes.Rect),
},
},
'adoptNode': {
params: {
frameId: t.String,
@ -823,8 +814,8 @@ const Page = {
'screenshot': {
params: {
mimeType: t.Enum(['image/png', 'image/jpeg']),
fullPage: t.Optional(t.Boolean),
clip: t.Optional(pageTypes.Clip),
omitDeviceScaleFactor: t.Optional(t.Boolean),
},
returns: {
data: t.String,